From d34c3b15d6bd9670086ad9231f2d7651ee121de5 Mon Sep 17 00:00:00 2001 From: Gal Szkolnik Date: Mon, 25 Jul 2022 15:03:24 -0400 Subject: [PATCH] Improved gcp_get_stack code: leaner/cleaner output --- _home/dot_sz.shrc.d/32_gcp.shortcuts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/_home/dot_sz.shrc.d/32_gcp.shortcuts b/_home/dot_sz.shrc.d/32_gcp.shortcuts index c9320ec..8d0e9c3 100644 --- a/_home/dot_sz.shrc.d/32_gcp.shortcuts +++ b/_home/dot_sz.shrc.d/32_gcp.shortcuts @@ -32,14 +32,17 @@ function gcp_get_region_quotas() { } function gcp_get_stack() { - local _cmd=$(printf 'N="%s"; CLOUDSDK_ACTIVE_CONFIG_NAME=dust-personal; echo $N; ' $1) - _cmd+='{ echo "Instances"; gcloud compute instances list --filter="name:$N"; } ' - _cmd+='&& { echo "Networks"; gcloud compute networks list --filter="name:$N"; } ' - _cmd+='&& {gcloud compute networks subnets list --filter="name:$N"} ' - _cmd+='&& {gcloud compute disks list --filter="name:$N"}' - _cmd='{ }' + local N="${1:-$(basename $PWD)}" + local _cmd="{ $(printf "%s " \ + "N='$N'; CLOUDSDK_ACTIVE_CONFIG_NAME=dust-personal; echo 'Listing $N stack:'; " \ + '{ gcloud compute instances list --filter="name:$N" | ' "sed s/^/Instances:\ /g ; } " \ + '&& { gcloud compute networks list --filter="name:$N" | ' "sed s/^/Networks.:\ /g ; } " \ + '&& { gcloud compute networks subnets list --filter="name:$N" | ' "sed s/^/Subnets..:\ /g ; } " \ + '&& { gcloud compute disks list --filter="name:$N" | ' "sed s/^/Disks....:\ /g ; } " \ + ) ;}" [ $# -ge 2 ] && _cmd="watch -n${2} '$_cmd'" - echo $_cmd + [[ -n ${SZ_DEBUG} ]] && printf "Executing: \n\t$_cmd\n\n" + eval $_cmd } # printf '\n\n'; gcp_get_stack 'dragonheart' 5