GCP SSH autocomplete with FZF and ZSH
I got inspired by AffectV post on AWS SSH completion and decided to write something similar for GCP.
Here’s the end result:
- You use zsh as your main shell
- You have fzf and its completion set up
Writing the module
First, we need to figure out how to get the list of information we want.
gcloud provides a somewhat sensible formatting and filtering options for that, e.g. if I want to get the name, zone and external IP of the instance in a flat tab-separated table, we’ll have to set options like so:
λ gcloud compute instances list \ --format="table[no-heading](name,zone,status,networkInterfaces.accessConfigs.natIP)" \ --filter="status=RUNNING" my-web-v37r australia-southeast1-c RUNNING XX.XXX.XX.XX my-web-wp2d australia-southeast1-c RUNNING XX.XXX.XX.XX my-worker-b96q
Continue reading →