Improvement to gcp_get_stack output

+ support for tmux to preserve height of pane
+ ability modify head while running
This commit is contained in:
Gal Szkolnik 2022-08-03 22:45:07 -04:00
parent 21a4bd288f
commit 1e2ad899eb
1 changed files with 16 additions and 7 deletions

View File

@ -31,16 +31,25 @@ function gcp_get_region_quotas() {
#done #done
} }
# Usage: gcp_get_stack dragonheart 10 22
# Watch the 'dragonheart' stack,
# refresh every 10 seconds,
# set tmux pane to 22 lines high (on every refresh)
function gcp_get_stack() { function gcp_get_stack() {
local N="${1:-$(basename $PWD)}" local N="${1:-$(basename $PWD)}"
local _cmd="{ $(printf "%s " \ local _cmd=""
"N='$N'; CLOUDSDK_ACTIVE_CONFIG_NAME=dust-personal; echo 'Listing $N stack:'; " \ local _tmux=''
'{ gcloud compute networks list --filter="name:$N" | ' "sed s/^/Networks.:\ /g ; } " \ [ $# -ge 3 ] && [[ -n "$(which-command tmux)" ]] && printf "%s" "$3" > "/tmp/tmux-$1" && _cmd=$(printf "%s" 'tmux resize-pane -t "$TMUX_PANE" -y $(cat "/tmp/tmux-' "$1" '") ; ') && eval $_cmd
'&& { gcloud compute networks subnets list --filter="name:$N" | ' "sed s/^/Subnets..:\ /g ; } " \ _cmd="{ $(printf "%s " \
'&& { gcloud compute disks list --filter="name:$N" | ' "sed s/^/Disks....:\ /g ; } " \ "N='$N'; " \
'&& { gcloud compute instances list --filter="name:$N" | ' "sed s/^/Instances:\ /g ; } " \ "${_cmd}" \
"echo 'Listing $N stack:'; " \
'{ gcloud compute networks list --filter="name:$N" | ' "sed --unbuffered s/^/Networks.:\ /g ; } " \
'&& { gcloud compute networks subnets list --filter="name:$N" | ' "sed --unbuffered s/^/Subnets..:\ /g ; } " \
'&& { gcloud compute disks list --filter="name:$N" | ' "sed --unbuffered s/^/Disks....:\ /g ; } " \
'&& { gcloud compute instances list --filter="name:$N" | ' "sed --unbuffered s/^/Instances:\ /g ; } " \
) ;}" ) ;}"
[ $# -ge 2 ] && _cmd="watch -n${2} '$_cmd'" [ $# -ge 2 ] && _cmd="watch -n${2} '${_cmd}'"
[[ -n ${SZ_DEBUG} ]] && printf "Executing: \n\t$_cmd\n\n" [[ -n ${SZ_DEBUG} ]] && printf "Executing: \n\t$_cmd\n\n"
eval $_cmd eval $_cmd
} }