Created
January 27, 2022 14:26
-
-
Save bechampion/6566dd1682da033fbab7a30522d8c787 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
#Caching meh | |
[[ -f /tmp/bmgprojcache ]] || touch /tmp/bmgprojcache | |
[[ -f /tmp/bmgvmcache ]] || touch /tmp/bmgvmcache | |
#if file is not even populated | |
if [[ $(find /tmp/bmgprojcache -mmin +60 -print) || $(wc /tmp/bmgprojcache | awk '{ print $1}') == 0 ]] | |
then | |
echo "re-caching projects" | |
gcloud projects list --format=json | jq '.[].projectId' -r > /tmp/bmgprojcache | |
fi | |
#fzf project | |
cat /tmp/bmgprojcache |fzf --height 30% --prompt "selectProject>"| xargs -I{} echo {} > /tmp/bmgproj | |
### | |
PROJECT=$(cat /tmp/bmgproj) | |
[[ -f /tmp/bmg${PROJECT}vmcache ]] || touch /tmp/bmg${PROJECT}vmcache | |
if [[ $(find /tmp/bmg${PROJECT}vmcache -mmin +60 -print) || $(wc /tmp/bmg${PROJECT}vmcache | awk '{ print $1}') == 0 ]] | |
then | |
gcloud compute instances list --project ${PROJECT} --format=json | jq '.[]|.name+" ["+.status+","+.networkInterfaces[].networkIP+"]"' -r | tee /tmp/bmg${PROJECT}vmcache | fzf --height 30% | xargs -I{} echo {} | awk '{ print $1}' > /tmp/bmgssh | |
else | |
cat /tmp/bmg${PROJECT}vmcache | fzf --height 30% --prompt "ssh>"| xargs -I{} echo {} | awk '{ print $1}' > /tmp/bmgssh | |
fi | |
gcloud compute ssh $(cat /tmp/bmgssh) --project $PROJECT --ssh-key-file=~/.ssh/id_rsa --ssh-flag="-t -v" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment