From a1256bb0afe224743b62226b8d39a1e2d52fc791 Mon Sep 17 00:00:00 2001 From: yage Date: Fri, 30 Sep 2022 20:23:37 -0600 Subject: [PATCH] v2.6.3 ===================================================================== --- Bug fixes ---------------------------- - s3/media-sync/push now pushes (instead of pull -- oops!) - fixed a typo in the launch-or-show help - environment actions no longer overwrite overwrite symlinks --- zsh/aws/s3/media-sync/common.zsh | 2 +- zsh/i3/launch-or-show | 3 ++- zsh/scwrypts/environment/common.zsh | 6 ++++-- zsh/scwrypts/environment/copy | 2 +- zsh/scwrypts/environment/edit | 2 +- zsh/scwrypts/environment/synchronize | 30 ++++++++++++++-------------- zsh/utils/io.zsh | 1 + 7 files changed, 25 insertions(+), 21 deletions(-) diff --git a/zsh/aws/s3/media-sync/common.zsh b/zsh/aws/s3/media-sync/common.zsh index 37922d4..eb2c7e8 100644 --- a/zsh/aws/s3/media-sync/common.zsh +++ b/zsh/aws/s3/media-sync/common.zsh @@ -24,7 +24,7 @@ __SYNC_MEDIA() { local FLAGS=(${@:3}) __STATUS "${ACTION}ing $2" - _AWS s3 sync $REMOTE_TARGET $LOCAL_TARGET $FLAGS \ + _AWS s3 sync $A $B $FLAGS \ && __SUCCESS "$2 up-to-date" \ || { __ERROR "unable to sync $2 (see above)"; return 1; } } diff --git a/zsh/i3/launch-or-show b/zsh/i3/launch-or-show index 1c4d4b5..1b0f46b 100755 --- a/zsh/i3/launch-or-show +++ b/zsh/i3/launch-or-show @@ -9,6 +9,7 @@ source ${0:a:h}/common.zsh ##################################################################### LAUNCH_OR_SHOW() { + __INFO $@ local USAGE=" usage: [client-class] [...options...] @@ -30,7 +31,7 @@ LAUNCH_OR_SHOW() { Depending on state, performs one of three useful functions 1) starts application 2) adds application window to the scratchpad - 3) pulls applciation from scratchpad to foreground on active screen + 3) pulls application from scratchpad to foreground on active screen " local APPLICATION CLIENT_CLASS diff --git a/zsh/scwrypts/environment/common.zsh b/zsh/scwrypts/environment/common.zsh index 683c83b..360cf75 100644 --- a/zsh/scwrypts/environment/common.zsh +++ b/zsh/scwrypts/environment/common.zsh @@ -6,7 +6,9 @@ source ${0:a:h}/../common.zsh _SORT_ENV() { local ENV_FILE="$1" - sed -i "/^# /d; /^$/d" "$ENV_FILE" - sed -i "s/^[A-Z]/export &/; s/^[^#=]\\+$/&=/" "$ENV_FILE" + _SED -i "/^# /d; /^$/d" "$ENV_FILE" + _SED -i "s/^[A-Z]/export &/; s/^[^#=]\\+$/&=/" "$ENV_FILE" LC_COLLATE=C sort -uo "$ENV_FILE" "$ENV_FILE" } + +_SED() { sed --follow-symlinks $@; } diff --git a/zsh/scwrypts/environment/copy b/zsh/scwrypts/environment/copy index 2b0fb99..7939a15 100755 --- a/zsh/scwrypts/environment/copy +++ b/zsh/scwrypts/environment/copy @@ -25,7 +25,7 @@ cp "$TEMPLATE_ENV_FILE" "$ENV_FILE" \ || __FAIL 3 "unable to create '$ENV_NAME'" __STATUS 'stripping inherited values' -sed -i 's/ # inherited from.*$//' "$ENV_FILE" 2>/dev/null +_SED -i 's/ # inherited from.*$//' "$ENV_FILE" 2>/dev/null __RUN_SCWRYPT zsh/scwrypts/environment/synchronize -- --no-prompt \ || __FAIL 4 'failed to run environment sync' diff --git a/zsh/scwrypts/environment/edit b/zsh/scwrypts/environment/edit index 09b6351..58c7f19 100755 --- a/zsh/scwrypts/environment/edit +++ b/zsh/scwrypts/environment/edit @@ -27,7 +27,7 @@ _SORT_ENV $ENV_FILE while read line do - ENV_VAR=$(echo "$line" | sed 's/=.*$//; s/^export //') + ENV_VAR=$(echo "$line" | _SED 's/=.*$//; s/^export //') grep -q "$ENV_VAR" $__ENV_TEMPLATE || { ((NEW_VAR+=1)) echo "export $ENV_VAR=" >> $__ENV_TEMPLATE diff --git a/zsh/scwrypts/environment/synchronize b/zsh/scwrypts/environment/synchronize index 65442ee..b0609e2 100755 --- a/zsh/scwrypts/environment/synchronize +++ b/zsh/scwrypts/environment/synchronize @@ -20,7 +20,7 @@ _SYNCHRONIZE() { } _SORT_ENV "$__ENV_TEMPLATE" - sed -i '/__[a-z_]\+=$/d' "$__ENV_TEMPLATE" + _SED -i '/__[a-z_]\+=$/d' "$__ENV_TEMPLATE" git add $__ENV_TEMPLATE >/dev/null 2>&1 ENVIRONMENTS=$(__GET_ENV_NAMES | sort -r) @@ -40,7 +40,7 @@ _CLEAR_INHERITED_VARIABLES() { for ENV_NAME in $(echo $ENVIRONMENTS) do ENV_FILE=$(__GET_ENV_FILE $ENV_NAME) - sed -i 's/ # inherited from.*//' "$ENV_FILE" + _SED -i 's/ # inherited from.*//' "$ENV_FILE" done } @@ -57,7 +57,7 @@ _INSERT_NEW_VARIABLES() { echo $line >> $ENV_FILE && __STATUS "added '$line' to '$ENV_NAME'" } done - done < <(sed -n '/^./p' "$__ENV_TEMPLATE") + done < <(_SED -n '/^./p' "$__ENV_TEMPLATE") } _REMOVE_OLD_VARIABLES() { @@ -69,11 +69,11 @@ _REMOVE_OLD_VARIABLES() { ENV_FILE=$(__GET_ENV_FILE $ENV_NAME) while read line do - ENV_VAR=$(echo "$line" | sed 's/=.*/=/') + ENV_VAR=$(echo "$line" | _SED 's/=.*/=/') echo $ENV_VAR | grep -q '__[a-z_]\+=' && continue grep -q "$ENV_VAR" "$__ENV_TEMPLATE" || { - sed -i "\\%$ENV_VAR%d" "$ENV_FILE" + _SED -i "\\%$ENV_VAR%d" "$ENV_FILE" echo "$ENV_VAR" | grep -qv '^#' \ && __WARNING "removed unwanted '$ENV_VAR' from '$ENV_NAME'" } @@ -114,8 +114,8 @@ _CASCADE_ENVIRONMENT() { while read PARENT_VAR do - VAR_PATTERN=$(echo "$PARENT_VAR" | sed 's/=.*/=/; s/\//\/\//g') - __STATUS "propagating '$(echo $VAR_PATTERN | sed 's/^export \([^=]*\)=/\1/')' to children" + VAR_PATTERN=$(echo "$PARENT_VAR" | _SED 's/=.*/=/; s/\//\/\//g') + __STATUS "propagating '$(echo $VAR_PATTERN | _SED 's/^export \([^=]*\)=/\1/')' to children" PARENT_VAR+=" # inherited from $PARENT_NAME" @@ -123,10 +123,10 @@ _CASCADE_ENVIRONMENT() { do CHILD_FILE=$(__GET_ENV_FILE $CHILD_NAME) - sed -i "/^$VAR_PATTERN/d" "$CHILD_FILE" + _SED -i "/^$VAR_PATTERN/d" "$CHILD_FILE" echo $PARENT_VAR >> "$CHILD_FILE" done - done < <(sed -n '/^[^#][^=]*=[^#]\+$/p' "$PARENT_FILE") + done < <(_SED -n '/^[^#][^=]*=[^#]\+$/p' "$PARENT_FILE") __SUCCESS "finished '$PARENT_NAME' propagation" } @@ -135,18 +135,18 @@ _ADD_DESCRIPTIONS() { __STATUS 'updating descriptions' while read DESCRIPTION_LINE do - ENV_VAR=$(echo $DESCRIPTION_LINE | sed 's/ \+| .*$//') - DESCRIPTION=$(echo $DESCRIPTION_LINE | sed 's/^.* | //') + ENV_VAR=$(echo $DESCRIPTION_LINE | _SED 's/ \+| .*$//') + DESCRIPTION=$(echo $DESCRIPTION_LINE | _SED 's/^.* | //') for ENV_NAME in $(echo $ENVIRONMENTS) do - sed -i "/^export $ENV_VAR=/i # $DESCRIPTION" "$(__GET_ENV_FILE $ENV_NAME)" + _SED -i "/^export $ENV_VAR=/i # $DESCRIPTION" "$(__GET_ENV_FILE $ENV_NAME)" done - done < <(sed -n '/^[^ ]\+ \+| /p' "$__ENV_TEMPLATE.descriptions") + done < <(_SED -n '/^[^ ]\+ \+| /p' "$__ENV_TEMPLATE.descriptions") for ENV_NAME in $(echo $ENVIRONMENTS) do - sed -i "/^# /i \ " "$(__GET_ENV_FILE $ENV_NAME)" - sed -i "s/^ $//" "$(__GET_ENV_FILE $ENV_NAME)" + _SED -i "/^# /i \ " "$(__GET_ENV_FILE $ENV_NAME)" + _SED -i "s/^ $//" "$(__GET_ENV_FILE $ENV_NAME)" done } diff --git a/zsh/utils/io.zsh b/zsh/utils/io.zsh index 15589d0..12d19bf 100644 --- a/zsh/utils/io.zsh +++ b/zsh/utils/io.zsh @@ -8,6 +8,7 @@ __PRINT() { printf "${COLOR}${MESSAGE}${__COLOR_RESET}${LINE_END}" } +[ ! $ERRORS ] && export ERRORS=0 __ERROR() { __PRINT $__RED "ERROR ✖ : $@" >&2; ((ERRORS+=1)); } __SUCCESS() { __PRINT $__GREEN "SUCCESS ✔ : $@" >&2; } __WARNING() { __PRINT $__ORANGE "WARNING  : $@" >&2; }