diff --git a/_home/.chezmoiexternal.toml b/_home/.chezmoiexternal.toml index 1e02e9a..2c8391c 100644 --- a/_home/.chezmoiexternal.toml +++ b/_home/.chezmoiexternal.toml @@ -1,3 +1,4 @@ +{{ if eq .chezmoi.hostname "pqb-laptop" }} [".local/share/git-on-web/chemacs2"] type = "git-repo" url = "https://github.com/plexus/chemacs2.git" @@ -14,6 +15,7 @@ url = "https://github.com/doomemacs/doomemacs" clone.args = ["--depth=1","--branch=develop","--single-branch"] refreshPeriod = "168h" # 7 days +{{ end }} # ["my/code/from_web/nerd-fonts"] # type = "git-repo" diff --git a/_home/dot_sz.shrc.d/11_direnv.env b/_home/dot_sz.shrc.d/11_direnv.env index 7fd5244..4efdd01 100644 --- a/_home/dot_sz.shrc.d/11_direnv.env +++ b/_home/dot_sz.shrc.d/11_direnv.env @@ -2,8 +2,15 @@ if [[ -n "$(which-command direnv)" ]]; then function _env() { if [[ -z "$_DIRENV_ShowEnvLogic" ]]; then echo "_DIRENV_ShowEnvLogic is not defined." - else - eval "$_DIRENV_ShowEnvLogic" | LC_ALL=C sort -h + if [[ $# -gt 0 ]]; then + local _DIRENV_ShowEnvLogic='printenv' + printf "Searching environment for: '${@}'\n\n" + fi + fi + if [[ -n "$_DIRENV_ShowEnvLogic" ]]; then + FILTER='' + [[ $# -gt 0 ]] && FILTER="| grep ${@}" + eval "$_DIRENV_ShowEnvLogic | LC_ALL=C sort -h $FILTER" fi } fi diff --git a/_home/dot_sz.shrc.d/32_gcp.shortcuts b/_home/dot_sz.shrc.d/32_gcp.shortcuts index b3598f9..c9320ec 100644 --- a/_home/dot_sz.shrc.d/32_gcp.shortcuts +++ b/_home/dot_sz.shrc.d/32_gcp.shortcuts @@ -1,21 +1,48 @@ function gcp_project() { - gcloud config get-value core/project 2> /dev/null + gcloud config get-value core/project 2> /dev/null } function gcp_get_project_id() { - gcloud projects list \ - --filter="$1" \ - --format="value(project_id)" \ - 2> /dev/null + gcloud projects list \ + --filter="$1" \ + --format="value(project_id)" \ + 2> /dev/null } function gcp_get_project_number() { - gcloud projects list \ - --filter="project_id:$1" \ - --format='value(project_number)' \ - 2> /dev/null + gcloud projects list \ + --filter="project_id:$1" \ + --format='value(project_number)' \ + 2> /dev/null +} +function gcp_get_regions() { + gcloud compute regions list --format="value(name)" } -function gcp_region() { - gcloud config get-value compute/region 2> /dev/null +function gcp_get_region_quotas() { + region_arr_list=( $(gcloud compute regions list --format="value(name)") ) + + for region in ${region_arr_list[@]}; do + echo -e $region\\\t$(gcloud compute regions describe $region --format="table(quotas:format='table(metric,limit,usage)')" | grep PREEMPTIBLE_CPUS ) + done + + #for region in {us-central1,us-east1,us-east4,us-west1,us-west2,us-west3,us-west4}; do + # echo -e $region\\\t$(gcloud compute regions describe $region --format="table(quotas:format='table(metric,limit,usage)')" | grep PREEMPTIBLE_CPUS ) + #done +} + +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='{ }' + [ $# -ge 2 ] && _cmd="watch -n${2} '$_cmd'" + echo $_cmd +} +# printf '\n\n'; gcp_get_stack 'dragonheart' 5 + +function gcp_region() { + gcloud config get-value compute/region 2> /dev/null } diff --git a/_home/dot_sz.shrc.d/33_terraform.shortcuts b/_home/dot_sz.shrc.d/33_terraform.shortcuts index 3c5711e..615cc07 100644 --- a/_home/dot_sz.shrc.d/33_terraform.shortcuts +++ b/_home/dot_sz.shrc.d/33_terraform.shortcuts @@ -14,6 +14,40 @@ if [[ -x $TERRAFORM_BIN ]]; then sed --unbuffered '/^===FULLSTOP===$/q' | sed --unbuffered '/^===FULLSTOP===$/d' } + function _tfless() { + local _TF_LOG_FILE=${1-_logs/0_0_lastrun.log} + [[ "$1" == "-" ]] && _TF_LOG_FILE='_logs/0_0_lastrun.log' + [[ -z "$SZ_DEBUG" ]] || echo "_tfless: ${@} | LESS_NO_WAIT = '${LESS_NO_WAIT}'" + [[ "$1" == "-" ]] && { + [[ -z "$SZ_DEBUG" ]] || echo "tailing..." + trap : INT; + tail -f $_TF_LOG_FILE | _tfsedFullStop; + } \ + || { [[ -z "${LESS_NO_WAIT}" ]] \ + && { + [[ -z "$SZ_DEBUG" ]] || echo "Invoking less..." + less \ + --no-init \ + --raw-control-chars \ + --line-numbers \ + --quiet \ + --hilite-unread \ + --incsearch \ + --ignore-case \ + --force \ + "${@:2}" -- \ + "$_TF_LOG_FILE" + #\ + #'+G?([^\w\W][\[0-9m+])Plan:' \ + #'+3k' + } + } + } + + function _tfSetLogTS() { + export TF_LOG_TS=$(date -d "today" +"%Y%m%d%H%M%S") + } + function tf() { [[ -z "$TF_LOG_TS" ]] && _tfSetLogTS local NAME=$1 @@ -31,10 +65,10 @@ if [[ -x $TERRAFORM_BIN ]]; then echo "===FULLSTOP===" >> _logs/0_0_lastrun.log } & - _tfless _logs/0_0_lastrun.log + _tfless - } - function tfp() { + function tf-plan() { [[ -z "$SZ_DEBUG" ]] || echo "DEBUG: tfplan ${@}" local _TF_TARGET="" [[ ${#TF_TARGET} -gt 0 ]] && _TF_TARGET="$(printf -- '--target=%s ' ${TF_TARGET[@]})" @@ -43,42 +77,36 @@ if [[ -x $TERRAFORM_BIN ]]; then tf plan ${_TF_TARGET} "${@}" } - function _tfless() { - local _TF_LOG_FILE=${1-_logs/0_0_lastrun.log} - [[ -z "$SZ_DEBUG" ]] || echo "_tfless: ${@} | LESS_NO_WAIT = '${LESS_NO_WAIT}'" - [[ -n "$1" ]] && { - trap : INT; - tail -f $_TF_LOG_FILE | _tfsedFullStop; - } \ - || { [[ -z "${LESS_NO_WAIT}" ]] \ - && { less \ - --no-init \ - --raw-control-chars \ - --line-numbers \ - --quiet \ - --hilite-unread \ - --incsearch \ - --ignore-case \ - --force \ - "${@:2}" -- \ - "$_TF_LOG_FILE" - #\ - #'+G?([^\w\W][\[0-9m+])Plan:' \ - #'+3k' - } + function get-tf-env() { + local PATTERN="${1-}" + compgen -v | grep "^TF_${PATTERN}" + } + + function clear-tf-env() { + local PATTERN="${1}" + local TOCLEAR=$(get-tf-env "${PATTERN}") + [[ -z "$TOCLEAR" ]] && { + echo "Could not find environment variables matching: $(echo "^TF_${PATTERN}")" + } || { + unset $TOCLEAR + echo "Cleared the following vars: $TOCLEAR" } } - function _tfSetLogTS() { - export TF_LOG_TS=$(date -d "today" +"%Y%m%d%H%M%S") + function clear-tf-env-vars() { + clear-tf-env 'VAR_[a-z]' } - function tfinit() { - return 0 + function clear-tf-env-targets() { + clear-tf-env '[A-Z_]*TARGET$' } - function tfplan() { - return 0 - } + alias tf-plan-destroy='tf-plan --destroy ' + alias tf-apply='tf apply ' + + alias tfp='tf-plan ' + alias tfpd='tf-plan-destroy ' + alias tfa='tf-apply ' + fi diff --git a/_home/dot_sz.shrc.d/bash.post/12_direnv.hook b/_home/dot_sz.shrc.d/bash.post/12_direnv.hook new file mode 100644 index 0000000..5d4faab --- /dev/null +++ b/_home/dot_sz.shrc.d/bash.post/12_direnv.hook @@ -0,0 +1,4 @@ +if [[ -n "$(type -fP direnv)" ]]; then + source <( direnv hook bash ) + source <( direnv stdlib ) +fi diff --git a/_home/dot_sz.shrc.d/bash.post/99_oh-my-posh.complete b/_home/dot_sz.shrc.d/bash.post/99_oh-my-posh.complete index c7a14fa..4308f9c 100644 --- a/_home/dot_sz.shrc.d/bash.post/99_oh-my-posh.complete +++ b/_home/dot_sz.shrc.d/bash.post/99_oh-my-posh.complete @@ -1 +1 @@ -[[ -n "$(type -fP gcloud)" ]] && source <(oh-my-posh completion bash) +[[ -n "$(which-command oh-my-posh)" ]] && source <(oh-my-posh completion bash)