From 4baacd9c3244690945189d935a6f4a57db438187 Mon Sep 17 00:00:00 2001 From: yage Date: Tue, 27 Jun 2023 05:00:06 -0600 Subject: [PATCH] v3.2.0 ===================================================================== --- Changes ------------------------------ - split up environment files per scwrypts group - updated i3/launch-or-show to provide some new options --- Bug Fixes ---------------------------- - utils/io commands like 'STATUS' no longer throw errors '%' characters - fixed ERROR_CHECK function calls to CHECK_ERRORS --- .env.template => .config/env.template | 0 .../env.template.descriptions | 0 run | 7 +- zsh/lib/config.group.zsh | 5 -- zsh/lib/import.driver.zsh | 11 ++- zsh/lib/scwrypts/environment-files.module.zsh | 76 ++++++++++++------- zsh/lib/scwrypts/run.module.zsh | 46 ++++++----- zsh/lib/utils/io.zsh | 8 +- zsh/scwrypts/environment/copy | 31 ++++---- zsh/scwrypts/environment/delete | 20 +++-- zsh/scwrypts/environment/edit | 28 ++++--- zsh/scwrypts/environment/stage-variables | 8 -- zsh/scwrypts/environment/synchronize | 54 +++++++------ zsh/system/i3/launch-or-show | 26 ++++++- zsh/system/packages/install | 2 +- 15 files changed, 202 insertions(+), 120 deletions(-) rename .env.template => .config/env.template (100%) rename .env.template.descriptions => .config/env.template.descriptions (100%) delete mode 100755 zsh/scwrypts/environment/stage-variables diff --git a/.env.template b/.config/env.template similarity index 100% rename from .env.template rename to .config/env.template diff --git a/.env.template.descriptions b/.config/env.template.descriptions similarity index 100% rename from .env.template.descriptions rename to .config/env.template.descriptions diff --git a/run b/run index 76c2c28..0cf8903 100755 --- a/run +++ b/run @@ -211,8 +211,11 @@ __RUN() { [[ $ENV_REQUIRED -eq 1 ]] && { [ ! $ENV_NAME ] && ENV_NAME=$(SCWRYPTS__SELECT_ENV) - local ENV_FILE=$(SCWRYPTS__GET_ENV_FILE "$ENV_NAME") - source "$ENV_FILE" || FAIL 5 "missing or invalid environment '$ENV_NAME'" + for GROUP in ${SCWRYPTS_GROUPS[@]} + do + local ENV_FILE=$(SCWRYPTS__GET_ENV_FILE "$ENV_NAME" "$GROUP") + source "$ENV_FILE" || FAIL 5 "missing or invalid environment '$GROUP/$ENV_NAME'" + done export ENV_NAME } diff --git a/zsh/lib/config.group.zsh b/zsh/lib/config.group.zsh index fd5329b..4f2b1b5 100644 --- a/zsh/lib/config.group.zsh +++ b/zsh/lib/config.group.zsh @@ -2,11 +2,6 @@ export SCWRYPTS_ROOT__scwrypts="$SCWRYPTS_ROOT" export SCWRYPTS_LIBRARY_ROOT__scwrypts="$SCWRYPTS_ROOT/zsh/lib" export SCWRYPTS_COLOR__scwrypts='\033[0;32m' -export SCWRYPTS_ENV_PATH__scwrypts="$SCWRYPTS_CONFIG_PATH/scwrypts/env" -[ ! -d "$SCWRYPTS_ENV_PATH__scwrypts" ] && mkdir -p "$SCWRYPTS_ENV_PATH__scwrypts" - -export SCWRYPTS_ENV_TEMPLATE__scwrypts="$SCWRYPTS_ROOT__scwrypts/.env.template" -export SCWRYPTS_ENV_TEMPLATE_DESCRIPTIONS__scwrypts="$SCWRYPTS_ROOT__scwrypts/.env.template.descriptions" export SCWRYPTS_VIRTUALENV_PATH__scwrypts="$SCWRYPTS_DATA_PATH/virtualenv" [ ! -d "$SCWRYPTS_VIRTUALENV_PATH__scwrypts" ] && mkdir -p "$SCWRYPTS_VIRTUALENV_PATH__scwrypts" diff --git a/zsh/lib/import.driver.zsh b/zsh/lib/import.driver.zsh index d466591..2d645e2 100644 --- a/zsh/lib/import.driver.zsh +++ b/zsh/lib/import.driver.zsh @@ -118,7 +118,16 @@ use() { } GET_SCWRYPTS_LIBRARY_ROOT() { - eval echo '$SCWRYPTS_LIBRARY_ROOT__'$SCWRYPTS_LIBRARY_GROUP + local ROOT + + ROOT=$(eval echo '$SCWRYPTS_LIBRARY_ROOT__'$SCWRYPTS_LIBRARY_GROUP) + [ $ROOT ] && echo $ROOT && return 0 + + [[ $(eval echo '$SCWRYPTS_TYPE__'$SCWRYPTS_LIBRARY_GROUP) =~ zsh ]] \ + && ROOT=$(eval echo '$SCWRYPTS_ROOT__'$SCWRYPTS_LIBRARY_GROUP/lib) \ + || ROOT=$(eval echo '$SCWRYPTS_ROOT__'$SCWRYPTS_LIBRARY_GROUP/zsh/lib) \ + ; + [ $ROOT ] && echo $ROOT && return 0 } IS_LOADED() { diff --git a/zsh/lib/scwrypts/environment-files.module.zsh b/zsh/lib/scwrypts/environment-files.module.zsh index 2c7402a..77800e9 100644 --- a/zsh/lib/scwrypts/environment-files.module.zsh +++ b/zsh/lib/scwrypts/environment-files.module.zsh @@ -15,20 +15,43 @@ SCWRYPTS__SELECT_OR_CREATE_ENV() { SCWRYPTS__GET_ENV_NAMES | FZF_TAIL 'select / create an environment' } -SCWRYPTS__GET_ENV_FILE() { +SCWRYPTS__GET_ENV_FILES() { local NAME="$1" - echo "$SCWRYPTS_ENV_PATH/$NAME" + local FILENAMES=$( + for GROUP in ${SCWRYPTS_GROUPS[@]} + do + echo "$SCWRYPTS_ENV_PATH/$GROUP/$NAME" + done + ) + + echo $FILENAMES | grep 'environments/scwrypts/' + echo $FILENAMES | grep -v 'environments/scwrypts/' | sort SCWRYPTS__GET_ENV_NAMES | grep -q $NAME \ || { ERROR "no environment '$NAME' exists"; return 1; } } +SCWRYPTS__GET_ENV_FILE() { + local NAME="$1" + local GROUP="$2" + + [ ! $GROUP ] && { ERROR 'must provide group'; return 1; } + + echo "$SCWRYPTS_ENV_PATH/$GROUP/$NAME" + + SCWRYPTS__GET_ENV_NAMES | grep -q $NAME \ + || { ERROR "no environment '$NAME' exists"; return 1; } + + [ -f "$SCWRYPTS_ENV_PATH/$GROUP/$NAME" ] \ + || { ERROR "missing environment file for '$GROUP/$NAME'"; return 2; } +} + SCWRYPTS__GET_ENV_TEMPLATE_FILES() { local GROUP for GROUP in ${SCWRYPTS_GROUPS[@]} do - eval echo '$SCWRYPTS_ENV_TEMPLATE__'$GROUP + eval echo '$SCWRYPTS_ROOT__'$GROUP/.config/env.template done } @@ -37,7 +60,7 @@ SCWRYPTS__GET_ENV_NAMES() { ERROR 'environment initialization error' return 1 } - ls "$SCWRYPTS_ENV_PATH" | sort -r + ls "$SCWRYPTS_ENV_PATH/scwrypts" | sort -r } SCWRYPTS__INIT_ENVIRONMENTS() { @@ -49,7 +72,11 @@ SCWRYPTS__INIT_ENVIRONMENTS() { local BASIC_ENV for BASIC_ENV in local dev prod do - GENERATE_TEMPLATE > "$SCWRYPTS_ENV_PATH/$BASIC_ENV" + for GROUP in ${SCWRYPTS_GROUPS[@]} + do + mkdir -p "$SCWRYPTS_ENV_PATH/$GROUP" + GENERATE_TEMPLATE > "$SCWRYPTS_ENV_PATH/$GROUP/$BASIC_ENV" + done done } @@ -58,30 +85,28 @@ SCWRYPTS__INIT_ENVIRONMENTS() { _SED() { sed --follow-symlinks $@; } GENERATE_TEMPLATE() { - echo "#!/bin/zsh" - echo '#####################################################################' - echo "### scwrypts runtime configuration ##################################" - echo '#####################################################################' - local FILE GROUP CONTENT - local VARIABLE DESCRIPTION - for GROUP in ${SCWRYPTS_GROUPS[@]} - do - FILE=$(eval echo '$SCWRYPTS_ENV_TEMPLATE__'$GROUP) + [ ! $GROUP ] && { ERROR 'must provide GROUP'; return 1; } + DIVIDER='#####################################################################' + HEADER='### scwrypts runtime configuration ' + [[ GROUP =~ ^scwrypts$ ]] || HEADER="${HEADER}(group '$GROUP') " + printf "#!/bin/zsh\n$DIVIDER\n$HEADER%s\n$DIVIDER\n" "${DIVIDER:${#$(echo "$HEADER")}}" - CONTENT=$(GET_VARIABLE_NAMES "$FILE" | sed 's/^/export /; s/$/=/') + local FILE CONTENT + local VARIABLE DESCRIPTION + FILE=$(eval echo '$SCWRYPTS_ROOT__'$GROUP/.config/env.template) - while read DESCRIPTION_LINE - do - VARIABLE=$(echo $DESCRIPTION_LINE | sed 's/ \+| .*$//') - DESCRIPTION=$(echo $DESCRIPTION_LINE | sed 's/^.* | //') - [ ! $DESCRIPTION ] && continue + CONTENT=$(GET_VARIABLE_NAMES "$FILE" | sed 's/^/export /; s/$/=/') - CONTENT=$(echo "$CONTENT" | sed "/^export $VARIABLE=/i #" | sed "/^export $VARIABLE=/i # $DESCRIPTION") - done < <(_SED -n '/^[^ ]\+ \+| /p' "$FILE.descriptions") + while read DESCRIPTION_LINE + do + VARIABLE=$(echo $DESCRIPTION_LINE | sed 's/ \+| .*$//') + DESCRIPTION=$(echo $DESCRIPTION_LINE | sed 's/^.* | //') + [ ! $DESCRIPTION ] && continue - echo "$CONTENT" | sed 's/^#$//' - echo '\n#####################################################################' - done + CONTENT=$(echo "$CONTENT" | sed "/^export $VARIABLE=/i #" | sed "/^export $VARIABLE=/i # $DESCRIPTION") + done < <(_SED -n '/^[^ ]\+ \+| /p' "$FILE.descriptions") + + echo "$CONTENT" | sed 's/^#$//' } GET_VARIABLE_NAMES() { @@ -91,4 +116,3 @@ GET_VARIABLE_NAMES() { | grep -v '__[a-z]\+$' \ ; } - diff --git a/zsh/lib/scwrypts/run.module.zsh b/zsh/lib/scwrypts/run.module.zsh index 2088e2c..8ee10c9 100644 --- a/zsh/lib/scwrypts/run.module.zsh +++ b/zsh/lib/scwrypts/run.module.zsh @@ -16,12 +16,16 @@ SCWRYPTS__GET_AVAILABLE_SCWRYPTS() { do GROUP_PATH=$(eval echo '$SCWRYPTS_ROOT__'$GROUP) GROUP_COLOR=$(eval echo '$SCWRYPTS_COLOR__'$GROUP) + + GROUP_TYPE=$(eval echo '$SCWRYPTS_TYPE__'$GROUP) + [ $GROUP_TYPE ] && MINDEPTH=1 && GROUP_TYPE="$GROUP_TYPE\\/" || MINDEPTH=2 + { cd "$GROUP_PATH" - find . -mindepth 2 -type f -executable \ + find . -mindepth $MINDEPTH -type f -executable \ | grep -v '\.git' \ | grep -v 'node_modules' \ - | sed "s/^\\.\\///; s/\\.[^.]*$//" \ + | sed "s/^\\.\\///; s/\\.[^.]*$//; s/^/$GROUP_TYPE/" \ | sed "s|\\([^/]*\\)/\(.*\)$|$(printf $__COLOR_RESET)\\2^$(printf $TYPE_COLOR)\\1^$(printf $GROUP_COLOR)$GROUP$(printf $__COLOR_RESET)|" \ ; } & @@ -43,53 +47,50 @@ SCWRYPTS__SEPARATE_SCWRYPT_SELECTION() { } SCWRYPTS__GET_RUNSTRING() { - # accepts a selected line from SCWRYPTS__GET_AVAILABLE_SCWRYPTS - local NAME="$1" - local TYPE="$2" - local GROUP="$3" - local GROUP_PATH=$(eval echo '$SCWRYPTS_ROOT__'$GROUP) + local GROUP_PATH=$(eval echo '$SCWRYPTS_ROOT__'$SCWRYPT_GROUP) local RUNSTRING - [ $NAME ] && [ $TYPE ] && [ $GROUP ] || { + [ $SCWRYPT_NAME ] && [ $SCWRYPT_TYPE ] && [ $SCWRYPT_GROUP ] || { ERROR 'missing required information to get runstring' return 1 } + [ $ENV_REQUIRED ] && [[ $ENV_REQUIRED -eq 1 ]] && [ ! $ENV_NAME ] && { ERROR 'missing required information to get runstring' return 1 } - typeset -f SCWRYPTS__GET_RUNSTRING__${GROUP}__${TYPE} >/dev/null 2>&1 && { - RUNSTRING=$(SCWRYPTS__GET_RUNSTRING__${GROUP}__${TYPE}) + typeset -f SCWRYPTS__GET_RUNSTRING__${SCWRYPT_GROUP}__${SCWRYPT_TYPE} >/dev/null 2>&1 && { + RUNSTRING=$(SCWRYPTS__GET_RUNSTRING__${SCWRYPT_GROUP}__${SCWRYPT_TYPE}) [ ! $RUNSTRING ] && { - ERROR "SCWRYPTS__GET_RUNSTRING__${GROUP}__${TYPE} error" + ERROR "SCWRYPTS__GET_RUNSTRING__${SCWRYPT_GROUP}__${SCWRYPT_TYPE} error" return 2 } } - typeset -f SCWRYPTS__GET_RUNSTRING__${TYPE} >/dev/null 2>&1 && { - RUNSTRING=$(SCWRYPTS__GET_RUNSTRING__${TYPE}) + typeset -f SCWRYPTS__GET_RUNSTRING__${SCWRYPT_TYPE} >/dev/null 2>&1 && { + RUNSTRING=$(SCWRYPTS__GET_RUNSTRING__${SCWRYPT_TYPE}) [ ! $RUNSTRING ] && { - ERROR "SCWRYPTS__GET_RUNSTRING__${TYPE} error" + ERROR "SCWRYPTS__GET_RUNSTRING__${SCWRYPT_TYPE} error" return 3 } } [ ! $RUNSTRING ] && { - ERROR "type ${TYPE} (group ${GROUP}) has no supported runstring generator" + ERROR "type ${SCWRYPT_TYPE} (group ${SCWRYPT_GROUP}) has no supported runstring generator" return 4 } RUNSTRING="SCWRYPTS_ENV=$ENV_NAME; $RUNSTRING" RUNSTRING="source $SCWRYPTS_ROOT/zsh/lib/import.driver.zsh; $RUNSTRING" - local _VIRTUALENV=$(eval echo '$SCWRYPTS_VIRTUALENV_PATH__'$GROUP'/$TYPE/bin/activate') + local _VIRTUALENV=$(eval echo '$SCWRYPTS_VIRTUALENV_PATH__'$SCWRYPT_GROUP'/$SCWRYPT_TYPE/bin/activate') [ -f $_VIRTUALENV ] && RUNSTRING="source $_VIRTUALENV; $RUNSTRING" local G SCWRYPTSENV for G in ${SCWRYPTS__GROUPS[@]} do - SCWRYPTSENV=$(eval echo '$SCWRYPTS_ENV_PATH__'$GROUP'/$ENV_NAME') + SCWRYPTSENV="$SCWRYPTS_ENV_PATH/$G/$ENV_NAME" [ -f $SCWRYPTSENV ] && RUNSTRING="source $SCWRYPTSENV; $RUNSTRING" done @@ -99,7 +100,12 @@ SCWRYPTS__GET_RUNSTRING() { SCWRYPTS__GET_RUNSTRING__zsh() { __CHECK_DEPENDENCY zsh || return 1 - echo "source $GROUP_PATH/$TYPE/$NAME" + [ $(eval echo '$SCWRYPTS_TYPE__'$SCWRYPT_GROUP) ] \ + && echo "source $GROUP_PATH/$SCWRYPT_NAME" \ + || echo "source $GROUP_PATH/$SCWRYPT_TYPE/$SCWRYPT_NAME" \ + ; + + return 0 } SCWRYPTS__GET_RUNSTRING__py() { @@ -110,11 +116,11 @@ SCWRYPTS__GET_RUNSTRING__py() { WARNING 'compatibility may vary' } - echo "cd $GROUP_PATH; python -m $(echo $TYPE/$NAME | sed 's/\//./g; s/\.py$//; s/\.\.//')" + echo "cd $GROUP_PATH; python -m $(echo $SCWRYPT_TYPE/$SCWRYPT_NAME | sed 's/\//./g; s/\.py$//; s/\.\.//')" } SCWRYPTS__GET_RUNSTRING__zx() { __CHECK_DEPENDENCY zx || return 1 - echo "export FORCE_COLOR=3; cd $GROUP_PATH; ./$TYPE/$NAME.js" + echo "export FORCE_COLOR=3; cd $GROUP_PATH; ./$SCWRYPT_TYPE/$SCWRYPT_NAME.js" } diff --git a/zsh/lib/utils/io.zsh b/zsh/lib/utils/io.zsh index ef9a78d..74529cc 100644 --- a/zsh/lib/utils/io.zsh +++ b/zsh/lib/utils/io.zsh @@ -16,7 +16,9 @@ PRINT() { shift 1 done - local STYLED_MESSAGE="${COLOR}$({ + MESSAGE="$(echo "$MESSAGE" | sed 's/%/%%/g')" + + local STYLED_MESSAGE="$({ printf "${COLOR}" while IFS='' read line do @@ -26,7 +28,9 @@ PRINT() { PREFIX=$(echo $PREFIX | sed 's/./ /g') done <<< $MESSAGE - })${__COLOR_RESET}${LAST_LINE_END}" + })" + STYLED_MESSAGE="${COLOR}$(echo "$STYLED_MESSAGE" | sed 's/%/%%/g')${__COLOR_RESET}${LAST_LINE_END}" + [[ $STDERR -eq 1 ]] && printf $STYLED_MESSAGE >&2 [[ $STDOUT -eq 1 ]] && printf $STYLED_MESSAGE diff --git a/zsh/scwrypts/environment/copy b/zsh/scwrypts/environment/copy index 5ce82c7..2bd7451 100755 --- a/zsh/scwrypts/environment/copy +++ b/zsh/scwrypts/environment/copy @@ -1,4 +1,4 @@ -#!/bin/zsh +#!/bin/zsh DEPENDENCIES+=() REQUIRED_ENV+=() @@ -16,18 +16,23 @@ STATUS "selected '$TEMPLATE_ENV_NAME'" PROMPT 'enter new environment name' ENV_NAME=$(echo '' | FZF_HEAD 'new environment') [ ! $ENV_NAME ] && ABORT +SCWRYPTS__GET_ENV_NAMES | grep -q $ENV_NAME && FAIL 1 "'$ENV_NAME' already exists" -TEMPLATE_ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $TEMPLATE_ENV_NAME 2>/dev/null) -ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $ENV_NAME) +for GROUP in ${SCWRYPTS_GROUPS[@]} +do + TEMPLATE_ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $TEMPLATE_ENV_NAME $GROUP 2>/dev/null) + ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $ENV_NAME $GROUP 2>/dev/null) -[ -f "$ENV_FILE" ] && FAIL 2 "'$ENV_NAME' already exists" + STATUS "creating environment '$ENV_NAME'" + cat "$TEMPLATE_ENV_FILE" \ + | sed 's/ # from.*//' \ + > "$ENV_FILE" \ + && SUCCESS "created '$ENV_FILE'" \ + || FAIL 2 "something went wrong creating '$ENV_FILE'" +done -STATUS "creating environment '$ENV_NAME'" -cat "$TEMPLATE_ENV_FILE" \ - | sed 's/ from.*//' \ - > "$ENV_FILE" \ - && SCWRYPTS__RUN --name scwrypts/environment/synchronize --group scwrypts --type zsh -- --no-prompt \ - && SUCCESS "created '$ENV_NAME'" \ - || FAIL 3 "something went wrong creating '$ENV_NAME'" - -SUCCESS "finished copy environment '$TEMPLATE_ENV_NAME > $ENV_NAME'" +STATUS "synchronizing environments" +SCWRYPTS__RUN --name scwrypts/environment/synchronize --group scwrypts --type zsh -- --no-prompt \ + && SUCCESS "finished copy environment '$TEMPLATE_ENV_NAME > $ENV_NAME'" \ + || FAIL 3 'error during synchronization of new environment (see above)' \ + ; diff --git a/zsh/scwrypts/environment/delete b/zsh/scwrypts/environment/delete index 63c29a7..bc64aa2 100755 --- a/zsh/scwrypts/environment/delete +++ b/zsh/scwrypts/environment/delete @@ -11,18 +11,26 @@ PROMPT 'choose an environment to delete' ENV_NAME=$(SCWRYPTS__SELECT_ENV) [ ! $ENV_NAME ] && ABORT -ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $ENV_NAME) +ENV_FILES=($(SCWRYPTS__GET_ENV_FILES $ENV_NAME)) STATUS "preparing to remove '$ENV_NAME'" WARNING " - the '$ENV_NAME' environment will be removed - configured options and stored credentials will be lost forever + the '$ENV_NAME' environment will be removed configured options + and stored credentials will be lost forever: + + $(echo $ENV_FILES | sed 's| /|\n - /|g; s/^/ - /') " yN 'continue?' || ABORT STATUS "removing environment" -rm "$ENV_FILE" \ - && SUCCESS "removed '$ENV_NAME'" \ - || FAIL 3 "unable to remove '$ENV_FILE'; is it protected?" +for ENV_FILE in ${ENV_FILES[@]} +do + rm "$ENV_FILE" \ + && SUCCESS "removed '$ENV_FILE'" \ + || ERROR "unable to remove '$ENV_FILE'; is it protected?" \ + ; +done + +CHECK_ERRORS -n || FAIL 2 "some errors ocurred when cleaning up $ENV_NAME" diff --git a/zsh/scwrypts/environment/edit b/zsh/scwrypts/environment/edit index 471fc92..858e7ef 100755 --- a/zsh/scwrypts/environment/edit +++ b/zsh/scwrypts/environment/edit @@ -16,16 +16,26 @@ CHECK_ENVIRONMENT } [ ! $ENV_NAME ] && ABORT -ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $ENV_NAME 2>/dev/null) -[ ! -f "$ENV_FILE" ] && { - STATUS "Creating '$ENV_NAME'..." \ - && touch "$ENV_FILE" \ - && SCWRYPTS__RUN --name scwrypts/environment/synchronize --group scwrypts --type zsh -- --no-prompt \ - && SUCCESS "created '$ENV_NAME'" \ - || { ERROR "failed to create '$ENV_FILE'"; exit 1; } -} +ENV_FILES=($(SCWRYPTS__GET_ENV_FILES $ENV_NAME 2>/dev/null)) +for ENV_FILE in ${ENV_FILES[@]} +do + [ ! -f "$ENV_FILE" ] && { + STATUS "Creating '$ENV_FILE'..." \ + && touch "$ENV_FILE" \ + && ((CREATED+=1)) \ + && SUCCESS "created '$ENV_NAME'" \ + || { ERROR "failed to create '$ENV_FILE'"; exit 1; } + } -EDIT $ENV_FILE + [ $CREATED ] && [[ $CREATED -gt 0 ]] && { + STATUS "detected new environment files; performing sync" \ + && SCWRYPTS__RUN --name scwrypts/environment/synchronize --group scwrypts --type zsh -- --no-prompt \ + || FAIL 1 "failure during sync for '$ENV_NAME'" \ + } + ; +done + +EDIT $ENV_FILES SCWRYPTS__RUN --name scwrypts/environment/synchronize --group scwrypts --type zsh -- --no-prompt \ || FAIL 4 'failed to run environment sync' \ diff --git a/zsh/scwrypts/environment/stage-variables b/zsh/scwrypts/environment/stage-variables deleted file mode 100755 index 2354bb7..0000000 --- a/zsh/scwrypts/environment/stage-variables +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/zsh -DEPENDENCIES+=() -REQUIRED_ENV+=() - -CHECK_ENVIRONMENT -##################################################################### - -__CHECK_REQUIRED_ENV $@ diff --git a/zsh/scwrypts/environment/synchronize b/zsh/scwrypts/environment/synchronize index 63b3088..bea43d0 100755 --- a/zsh/scwrypts/environment/synchronize +++ b/zsh/scwrypts/environment/synchronize @@ -49,39 +49,47 @@ SYNCHRONIZE() { local ENVIRONMENTS ENVIRONMENT_FILES local FILE NAME ENVIRONMENT_FILE - ENVIRONMENTS=($(SCWRYPTS__GET_ENV_NAMES | sort -r)) - ENVIRONMENT_FILES=($( + GROUP_PIDS=() + for GROUP in ${SCWRYPTS_GROUPS} + do + { + ENVIRONMENTS=($(SCWRYPTS__GET_ENV_NAMES | sort -r)) + ENVIRONMENT_FILES=($( + for NAME in ${ENVIRONMENTS[@]} + do + SCWRYPTS__GET_ENV_FILE $NAME $GROUP + done + )) + + STATUS 'generating working environment files...' + for FILE in ${ENVIRONMENT_FILES[@]} + do + GENERATE_TEMP_ENVIRONMENT_FILE "$FILE" + done + + STATUS 'cascading environment values to children...' for NAME in ${ENVIRONMENTS[@]} do - SCWRYPTS__GET_ENV_FILE $NAME + CASCADE_ENVIRONMENT $NAME done - )) - STATUS 'generating working environment files...' - for FILE in ${ENVIRONMENT_FILES[@]} - do - GENERATE_TEMP_ENVIRONMENT_FILE "$FILE" + STATUS 'cleaning up working space...' + for FILE in ${ENVIRONMENT_FILES[@]} + do + CLEANUP_ENVIRONMENT_FILE "$FILE" + done + SUCCESS 'finished sync!' + } & + GROUP_PIDS+=$! done - - STATUS 'cascading environment values to children...' - for NAME in ${ENVIRONMENTS[@]} - do - CASCADE_ENVIRONMENT $NAME - done - - STATUS 'cleaning up working space...' - for FILE in ${ENVIRONMENT_FILES[@]} - do - CLEANUP_ENVIRONMENT_FILE "$FILE" - done - SUCCESS 'finished sync!' + for P in ${GROUP_PIDS[@]}; do wait $P; done } ##################################################################### CASCADE_ENVIRONMENT() { local PARENT_NAME="$1" - local PARENT_FILE="$(SCWRYPTS__GET_ENV_FILE $PARENT_NAME).temp" + local PARENT_FILE="$(SCWRYPTS__GET_ENV_FILE $PARENT_NAME $GROUP).temp" local CHILD_NAMES=($(echo $ENVIRONMENTS | sed 's/ \+/\n/g' |grep "^$PARENT_NAME\\.")) [[ ${#CHILD_NAMES[@]} -eq 0 ]] && return 0 @@ -93,7 +101,7 @@ CASCADE_ENVIRONMENT() { for CHILD_NAME in ${CHILD_NAMES[@]} do STATUS "propagating environment '$PARENT_NAME' to child '$CHILD_NAME'" - CHILD_FILE="$(SCWRYPTS__GET_ENV_FILE $CHILD_NAME).temp" + CHILD_FILE="$(SCWRYPTS__GET_ENV_FILE $CHILD_NAME $GROUP).temp" CONTENT=$(cat "$CHILD_FILE") echo "$PARENT_VARIABLES" | ADD_LINES echo "$CONTENT" > "$CHILD_FILE" diff --git a/zsh/system/i3/launch-or-show b/zsh/system/i3/launch-or-show index d8275c3..47a360f 100755 --- a/zsh/system/i3/launch-or-show +++ b/zsh/system/i3/launch-or-show @@ -25,6 +25,9 @@ LAUNCH_OR_SHOW() { -a, --always-launch invoke executable even if client-class exists -n, --no-resize don't resize the window (ignores -sxy flags) + -l, --no-center leave the window wherever it was last positioned + + --has-statusbar-icon (default: false) use if program has a statusbar icon -h, --help print this message and exit @@ -47,6 +50,8 @@ LAUNCH_OR_SHOW() { local ALWAYS_LAUNCH=0 local RESIZE=1 + local MOVE=1 + local MIN_ACTIVE=1 while [[ $# -gt 0 ]] do @@ -58,6 +63,9 @@ LAUNCH_OR_SHOW() { -a | --always-launch ) ALWAYS_LAUNCH=1 ;; -n | --no-resize ) RESIZE=0 ;; + -l | --no-center ) MOVE=0 ;; + + --has-statusbar-icon ) MIN_ACTIVE=2 ;; -h | --help ) USAGE; exit 0 ;; @@ -78,7 +86,13 @@ LAUNCH_OR_SHOW() { } } - ERROR_CHECK + CHECK_ERRORS + + xrandr | grep primary | awk '{print $4;}' | grep -q '^[0-9]\+$' || { + xrandr --output $(xrandr | grep ' connected' | awk '{print $1;}' | head -n1) --primary + } + + local CURRENTLY_ACTIVE=$(xdotool search --onlyvisible --classname $CLIENT_CLASS 2>/dev/null | wc -l) local LAUNCH_APP=$ALWAYS_LAUNCH STATUS "looking for window process ids" @@ -107,11 +121,15 @@ LAUNCH_OR_SHOW() { && STATUS 'resizing window' \ && i3-msg "[class=$CLIENT_CLASS] resize set $WINDOW_SIZE" - STATUS 'pulling window from scratchpad to foreground' - i3-msg "[class=$CLIENT_CLASS] scratchpad show" + [[ $CURRENTLY_ACTIVE -lt $MIN_ACTIVE ]] && { + STATUS 'pulling window from scratchpad to foreground' + i3-msg "[class=$CLIENT_CLASS] scratchpad show" + } STATUS 'moving window to center of current screen' - i3-msg "[class=$CLIENT_CLASS] move position center" + [[ $MOVE -eq 1 ]] && i3-msg "[class=$CLIENT_CLASS] move position center" + + return 0 } ##################################################################### diff --git a/zsh/system/packages/install b/zsh/system/packages/install index 92b3086..4abe529 100755 --- a/zsh/system/packages/install +++ b/zsh/system/packages/install @@ -65,7 +65,7 @@ INSTALL() { } } - ERROR_CHECK + CHECK_ERRORS ####################################################