Last active
June 30, 2022 22:08
-
-
Save JohnMcSpedon/1c96fd7bdb6784e0b101240407a64fb0 to your computer and use it in GitHub Desktop.
bash utils for easier use of GCP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias glist="gcloud compute instances list | grep -v TERMINATED" | |
alias gssh="gcloud compute ssh --ssh-flag=\"-A\"" | |
function gdel { | |
gcloud compute instances delete $@ | |
} | |
GCLOUD_DIR="$HOME/.config/gcloud" | |
function switch_gcp_project { | |
if [[ $# -ne 1 ]]; then | |
echo "Expected usage: \$ switch_gcp_project <project name>" | |
echo "" | |
echo " Example: switch_gcp_project my-gcp-project" | |
return 1 | |
fi | |
if [[ ! -f $GCLOUD_DIR/configurations/config_$1 ]]; then | |
echo "Configuration '$1' does not exist." | |
echo "Existing configurations:" | |
gcloud config configurations list | |
return 2 | |
fi | |
gcloud config configurations activate $1 | |
# When you do `cp src dest` and `dest` exists already, | |
# zsh/prezto's default behavior is to ask you if you really want to override. | |
# That is why we use `\cp src dest` (https://superuser.com/questions/179865/how-does-cp-work) | |
\cp $GCLOUD_DIR/application_default_credentials.json.$1 \ | |
$GCLOUD_DIR/application_default_credentials.json | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment