Skip to content

Instantly share code, notes, and snippets.

@marcosinger
Created October 16, 2019 19:40
Show Gist options
  • Save marcosinger/84d2df6075b1839be4fc4fe0ac8e951c to your computer and use it in GitHub Desktop.
Save marcosinger/84d2df6075b1839be4fc4fe0ac8e951c to your computer and use it in GitHub Desktop.
Fish helpers to handle with gcloud config
# ~/.config/completions/gswitch.fish
#
# creates a variable with the name of gcloud named configurations. Ex.:
#
# ~ glist
# NAME IS_ACTIVE ACCOUNT PROJECT
# aluminium False [email protected] aluminium-123
# nickel True [email protected] nickel-001
# zinc False [email protected] zinc-project
#
# echo $project
# > aluminium nickel zinc
set -l projects (glist | tail -n +2 | awk '{print $1}')
# autocomplete function gswitch based on $projects variable
# https://fishshell.com/docs/current/index.html#completion
complete -c gswitch -x -a '$projects'
# ~/.config/functions/glist.fish
function glist -d 'List gcloud named configurations'
gcloud config configurations list
end
# ~/.config/functions/gswitch.fish
function gswitch -d 'Switch between gcloud configurations'
gcloud config configurations activate $argv
end
@marcosinger
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment