General housekeeping tasks

This commit is contained in:
Gal Szkolnik 2022-07-25 11:21:39 -04:00
parent d1fe086f7c
commit 9f1181ae02
6 changed files with 114 additions and 46 deletions

View File

@ -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"

View File

@ -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

View File

@ -15,6 +15,33 @@ function gcp_get_project_number() {
--format='value(project_number)' \
2> /dev/null
}
function gcp_get_regions() {
gcloud compute regions list --format="value(name)"
}
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

View File

@ -14,44 +14,19 @@ if [[ -x $TERRAFORM_BIN ]]; then
sed --unbuffered '/^===FULLSTOP===$/q' | sed --unbuffered '/^===FULLSTOP===$/d'
}
function tf() {
[[ -z "$TF_LOG_TS" ]] && _tfSetLogTS
local NAME=$1
[[ "${@}" =~ "-destroy" ]] && NAME="$1-destroy"
echo "===_logs/0_$NAME.log===" > _logs/0_0_lastrun.log
[[ -z "$SZ_DEBUG" ]] || echo "Executing: terraform ${@}"
{
terraform "${@}" 2>&1 \
| tee _logs/${TF_LOG_TS}_$NAME.log \
| awk 'BEGIN {p=1}; /<<\W*EOT/ {print; p=0}; /^\W*EOT/ {p=1}; p; fflush();' \
| tee --append _logs/0_0_lastrun.log \
>> _logs/0_$NAME.log
echo "===FULLSTOP===" >> _logs/0_0_lastrun.log
} &
_tfless _logs/0_0_lastrun.log
}
function tfp() {
[[ -z "$SZ_DEBUG" ]] || echo "DEBUG: tfplan ${@}"
local _TF_TARGET=""
[[ ${#TF_TARGET} -gt 0 ]] && _TF_TARGET="$(printf -- '--target=%s ' ${TF_TARGET[@]})"
[[ "${@}" =~ "-destroy" ]] && [[ ${#TF_DESTROY_TARGET} -gt 0 ]] && _TF_TARGET="$(printf -- '--target=%s ' ${TF_DESTROY_TARGET[@]})"
tf plan ${_TF_TARGET} "${@}"
}
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}'"
[[ -n "$1" ]] && {
[[ "$1" == "-" ]] && {
[[ -z "$SZ_DEBUG" ]] || echo "tailing..."
trap : INT;
tail -f $_TF_LOG_FILE | _tfsedFullStop;
} \
|| { [[ -z "${LESS_NO_WAIT}" ]] \
&& { less \
&& {
[[ -z "$SZ_DEBUG" ]] || echo "Invoking less..."
less \
--no-init \
--raw-control-chars \
--line-numbers \
@ -73,12 +48,65 @@ if [[ -x $TERRAFORM_BIN ]]; then
export TF_LOG_TS=$(date -d "today" +"%Y%m%d%H%M%S")
}
function tfinit() {
return 0
function tf() {
[[ -z "$TF_LOG_TS" ]] && _tfSetLogTS
local NAME=$1
[[ "${@}" =~ "-destroy" ]] && NAME="$1-destroy"
echo "===_logs/0_$NAME.log===" > _logs/0_0_lastrun.log
[[ -z "$SZ_DEBUG" ]] || echo "Executing: terraform ${@}"
{
terraform "${@}" 2>&1 \
| tee _logs/${TF_LOG_TS}_$NAME.log \
| awk 'BEGIN {p=1}; /<<\W*EOT/ {print; p=0}; /^\W*EOT/ {p=1}; p; fflush();' \
| tee --append _logs/0_0_lastrun.log \
>> _logs/0_$NAME.log
echo "===FULLSTOP===" >> _logs/0_0_lastrun.log
} &
_tfless -
}
function tfplan() {
return 0
function tf-plan() {
[[ -z "$SZ_DEBUG" ]] || echo "DEBUG: tfplan ${@}"
local _TF_TARGET=""
[[ ${#TF_TARGET} -gt 0 ]] && _TF_TARGET="$(printf -- '--target=%s ' ${TF_TARGET[@]})"
[[ "${@}" =~ "-destroy" ]] && [[ ${#TF_DESTROY_TARGET} -gt 0 ]] && _TF_TARGET="$(printf -- '--target=%s ' ${TF_DESTROY_TARGET[@]})"
tf plan ${_TF_TARGET} "${@}"
}
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 clear-tf-env-vars() {
clear-tf-env 'VAR_[a-z]'
}
function clear-tf-env-targets() {
clear-tf-env '[A-Z_]*TARGET$'
}
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

View File

@ -0,0 +1,4 @@
if [[ -n "$(type -fP direnv)" ]]; then
source <( direnv hook bash )
source <( direnv stdlib )
fi

View File

@ -1 +1 @@
[[ -n "$(type -fP gcloud)" ]] && source <(oh-my-posh completion bash)
[[ -n "$(which-command oh-my-posh)" ]] && source <(oh-my-posh completion bash)