=====================================================================

--- 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
This commit is contained in:
Wryn (yage) Wagner 2023-06-27 05:00:06 -06:00
parent 6c546ebb6f
commit 4baacd9c32
15 changed files with 202 additions and 120 deletions

7
run
View File

@ -211,8 +211,11 @@ __RUN() {
[[ $ENV_REQUIRED -eq 1 ]] && { [[ $ENV_REQUIRED -eq 1 ]] && {
[ ! $ENV_NAME ] && ENV_NAME=$(SCWRYPTS__SELECT_ENV) [ ! $ENV_NAME ] && ENV_NAME=$(SCWRYPTS__SELECT_ENV)
local ENV_FILE=$(SCWRYPTS__GET_ENV_FILE "$ENV_NAME") for GROUP in ${SCWRYPTS_GROUPS[@]}
source "$ENV_FILE" || FAIL 5 "missing or invalid environment '$ENV_NAME'" 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 export ENV_NAME
} }

View File

@ -2,11 +2,6 @@ export SCWRYPTS_ROOT__scwrypts="$SCWRYPTS_ROOT"
export SCWRYPTS_LIBRARY_ROOT__scwrypts="$SCWRYPTS_ROOT/zsh/lib" export SCWRYPTS_LIBRARY_ROOT__scwrypts="$SCWRYPTS_ROOT/zsh/lib"
export SCWRYPTS_COLOR__scwrypts='\033[0;32m' 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" export SCWRYPTS_VIRTUALENV_PATH__scwrypts="$SCWRYPTS_DATA_PATH/virtualenv"
[ ! -d "$SCWRYPTS_VIRTUALENV_PATH__scwrypts" ] && mkdir -p "$SCWRYPTS_VIRTUALENV_PATH__scwrypts" [ ! -d "$SCWRYPTS_VIRTUALENV_PATH__scwrypts" ] && mkdir -p "$SCWRYPTS_VIRTUALENV_PATH__scwrypts"

View File

@ -118,7 +118,16 @@ use() {
} }
GET_SCWRYPTS_LIBRARY_ROOT() { 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() { IS_LOADED() {

View File

@ -15,20 +15,43 @@ SCWRYPTS__SELECT_OR_CREATE_ENV() {
SCWRYPTS__GET_ENV_NAMES | FZF_TAIL 'select / create an environment' SCWRYPTS__GET_ENV_NAMES | FZF_TAIL 'select / create an environment'
} }
SCWRYPTS__GET_ENV_FILE() { SCWRYPTS__GET_ENV_FILES() {
local NAME="$1" 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 \ SCWRYPTS__GET_ENV_NAMES | grep -q $NAME \
|| { ERROR "no environment '$NAME' exists"; return 1; } || { 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() { SCWRYPTS__GET_ENV_TEMPLATE_FILES() {
local GROUP local GROUP
for GROUP in ${SCWRYPTS_GROUPS[@]} for GROUP in ${SCWRYPTS_GROUPS[@]}
do do
eval echo '$SCWRYPTS_ENV_TEMPLATE__'$GROUP eval echo '$SCWRYPTS_ROOT__'$GROUP/.config/env.template
done done
} }
@ -37,7 +60,7 @@ SCWRYPTS__GET_ENV_NAMES() {
ERROR 'environment initialization error' ERROR 'environment initialization error'
return 1 return 1
} }
ls "$SCWRYPTS_ENV_PATH" | sort -r ls "$SCWRYPTS_ENV_PATH/scwrypts" | sort -r
} }
SCWRYPTS__INIT_ENVIRONMENTS() { SCWRYPTS__INIT_ENVIRONMENTS() {
@ -49,7 +72,11 @@ SCWRYPTS__INIT_ENVIRONMENTS() {
local BASIC_ENV local BASIC_ENV
for BASIC_ENV in local dev prod for BASIC_ENV in local dev prod
do 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 done
} }
@ -58,15 +85,15 @@ SCWRYPTS__INIT_ENVIRONMENTS() {
_SED() { sed --follow-symlinks $@; } _SED() { sed --follow-symlinks $@; }
GENERATE_TEMPLATE() { GENERATE_TEMPLATE() {
echo "#!/bin/zsh" [ ! $GROUP ] && { ERROR 'must provide GROUP'; return 1; }
echo '#####################################################################' DIVIDER='#####################################################################'
echo "### scwrypts runtime configuration ##################################" HEADER='### scwrypts runtime configuration '
echo '#####################################################################' [[ GROUP =~ ^scwrypts$ ]] || HEADER="${HEADER}(group '$GROUP') "
local FILE GROUP CONTENT printf "#!/bin/zsh\n$DIVIDER\n$HEADER%s\n$DIVIDER\n" "${DIVIDER:${#$(echo "$HEADER")}}"
local FILE CONTENT
local VARIABLE DESCRIPTION local VARIABLE DESCRIPTION
for GROUP in ${SCWRYPTS_GROUPS[@]} FILE=$(eval echo '$SCWRYPTS_ROOT__'$GROUP/.config/env.template)
do
FILE=$(eval echo '$SCWRYPTS_ENV_TEMPLATE__'$GROUP)
CONTENT=$(GET_VARIABLE_NAMES "$FILE" | sed 's/^/export /; s/$/=/') CONTENT=$(GET_VARIABLE_NAMES "$FILE" | sed 's/^/export /; s/$/=/')
@ -80,8 +107,6 @@ GENERATE_TEMPLATE() {
done < <(_SED -n '/^[^ ]\+ \+| /p' "$FILE.descriptions") done < <(_SED -n '/^[^ ]\+ \+| /p' "$FILE.descriptions")
echo "$CONTENT" | sed 's/^#$//' echo "$CONTENT" | sed 's/^#$//'
echo '\n#####################################################################'
done
} }
GET_VARIABLE_NAMES() { GET_VARIABLE_NAMES() {
@ -91,4 +116,3 @@ GET_VARIABLE_NAMES() {
| grep -v '__[a-z]\+$' \ | grep -v '__[a-z]\+$' \
; ;
} }

View File

@ -16,12 +16,16 @@ SCWRYPTS__GET_AVAILABLE_SCWRYPTS() {
do do
GROUP_PATH=$(eval echo '$SCWRYPTS_ROOT__'$GROUP) GROUP_PATH=$(eval echo '$SCWRYPTS_ROOT__'$GROUP)
GROUP_COLOR=$(eval echo '$SCWRYPTS_COLOR__'$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" cd "$GROUP_PATH"
find . -mindepth 2 -type f -executable \ find . -mindepth $MINDEPTH -type f -executable \
| grep -v '\.git' \ | grep -v '\.git' \
| grep -v 'node_modules' \ | 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)|" \ | 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() { SCWRYPTS__GET_RUNSTRING() {
# accepts a selected line from SCWRYPTS__GET_AVAILABLE_SCWRYPTS local GROUP_PATH=$(eval echo '$SCWRYPTS_ROOT__'$SCWRYPT_GROUP)
local NAME="$1"
local TYPE="$2"
local GROUP="$3"
local GROUP_PATH=$(eval echo '$SCWRYPTS_ROOT__'$GROUP)
local RUNSTRING local RUNSTRING
[ $NAME ] && [ $TYPE ] && [ $GROUP ] || { [ $SCWRYPT_NAME ] && [ $SCWRYPT_TYPE ] && [ $SCWRYPT_GROUP ] || {
ERROR 'missing required information to get runstring' ERROR 'missing required information to get runstring'
return 1 return 1
} }
[ $ENV_REQUIRED ] && [[ $ENV_REQUIRED -eq 1 ]] && [ ! $ENV_NAME ] && { [ $ENV_REQUIRED ] && [[ $ENV_REQUIRED -eq 1 ]] && [ ! $ENV_NAME ] && {
ERROR 'missing required information to get runstring' ERROR 'missing required information to get runstring'
return 1 return 1
} }
typeset -f SCWRYPTS__GET_RUNSTRING__${GROUP}__${TYPE} >/dev/null 2>&1 && { typeset -f SCWRYPTS__GET_RUNSTRING__${SCWRYPT_GROUP}__${SCWRYPT_TYPE} >/dev/null 2>&1 && {
RUNSTRING=$(SCWRYPTS__GET_RUNSTRING__${GROUP}__${TYPE}) RUNSTRING=$(SCWRYPTS__GET_RUNSTRING__${SCWRYPT_GROUP}__${SCWRYPT_TYPE})
[ ! $RUNSTRING ] && { [ ! $RUNSTRING ] && {
ERROR "SCWRYPTS__GET_RUNSTRING__${GROUP}__${TYPE} error" ERROR "SCWRYPTS__GET_RUNSTRING__${SCWRYPT_GROUP}__${SCWRYPT_TYPE} error"
return 2 return 2
} }
} }
typeset -f SCWRYPTS__GET_RUNSTRING__${TYPE} >/dev/null 2>&1 && { typeset -f SCWRYPTS__GET_RUNSTRING__${SCWRYPT_TYPE} >/dev/null 2>&1 && {
RUNSTRING=$(SCWRYPTS__GET_RUNSTRING__${TYPE}) RUNSTRING=$(SCWRYPTS__GET_RUNSTRING__${SCWRYPT_TYPE})
[ ! $RUNSTRING ] && { [ ! $RUNSTRING ] && {
ERROR "SCWRYPTS__GET_RUNSTRING__${TYPE} error" ERROR "SCWRYPTS__GET_RUNSTRING__${SCWRYPT_TYPE} error"
return 3 return 3
} }
} }
[ ! $RUNSTRING ] && { [ ! $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 return 4
} }
RUNSTRING="SCWRYPTS_ENV=$ENV_NAME; $RUNSTRING" RUNSTRING="SCWRYPTS_ENV=$ENV_NAME; $RUNSTRING"
RUNSTRING="source $SCWRYPTS_ROOT/zsh/lib/import.driver.zsh; $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" [ -f $_VIRTUALENV ] && RUNSTRING="source $_VIRTUALENV; $RUNSTRING"
local G SCWRYPTSENV local G SCWRYPTSENV
for G in ${SCWRYPTS__GROUPS[@]} for G in ${SCWRYPTS__GROUPS[@]}
do do
SCWRYPTSENV=$(eval echo '$SCWRYPTS_ENV_PATH__'$GROUP'/$ENV_NAME') SCWRYPTSENV="$SCWRYPTS_ENV_PATH/$G/$ENV_NAME"
[ -f $SCWRYPTSENV ] && RUNSTRING="source $SCWRYPTSENV; $RUNSTRING" [ -f $SCWRYPTSENV ] && RUNSTRING="source $SCWRYPTSENV; $RUNSTRING"
done done
@ -99,7 +100,12 @@ SCWRYPTS__GET_RUNSTRING() {
SCWRYPTS__GET_RUNSTRING__zsh() { SCWRYPTS__GET_RUNSTRING__zsh() {
__CHECK_DEPENDENCY zsh || return 1 __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() { SCWRYPTS__GET_RUNSTRING__py() {
@ -110,11 +116,11 @@ SCWRYPTS__GET_RUNSTRING__py() {
WARNING 'compatibility may vary' 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() { SCWRYPTS__GET_RUNSTRING__zx() {
__CHECK_DEPENDENCY zx || return 1 __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"
} }

View File

@ -16,7 +16,9 @@ PRINT() {
shift 1 shift 1
done done
local STYLED_MESSAGE="${COLOR}$({ MESSAGE="$(echo "$MESSAGE" | sed 's/%/%%/g')"
local STYLED_MESSAGE="$({
printf "${COLOR}" printf "${COLOR}"
while IFS='' read line while IFS='' read line
do do
@ -26,7 +28,9 @@ PRINT() {
PREFIX=$(echo $PREFIX | sed 's/./ /g') PREFIX=$(echo $PREFIX | sed 's/./ /g')
done <<< $MESSAGE 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 [[ $STDERR -eq 1 ]] && printf $STYLED_MESSAGE >&2
[[ $STDOUT -eq 1 ]] && printf $STYLED_MESSAGE [[ $STDOUT -eq 1 ]] && printf $STYLED_MESSAGE

View File

@ -16,18 +16,23 @@ STATUS "selected '$TEMPLATE_ENV_NAME'"
PROMPT 'enter new environment name' PROMPT 'enter new environment name'
ENV_NAME=$(echo '' | FZF_HEAD 'new environment') ENV_NAME=$(echo '' | FZF_HEAD 'new environment')
[ ! $ENV_NAME ] && ABORT [ ! $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) for GROUP in ${SCWRYPTS_GROUPS[@]}
ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $ENV_NAME) do
TEMPLATE_ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $TEMPLATE_ENV_NAME $GROUP 2>/dev/null)
[ -f "$ENV_FILE" ] && FAIL 2 "'$ENV_NAME' already exists" ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $ENV_NAME $GROUP 2>/dev/null)
STATUS "creating environment '$ENV_NAME'" STATUS "creating environment '$ENV_NAME'"
cat "$TEMPLATE_ENV_FILE" \ cat "$TEMPLATE_ENV_FILE" \
| sed 's/ from.*//' \ | sed 's/ # from.*//' \
> "$ENV_FILE" \ > "$ENV_FILE" \
&& SCWRYPTS__RUN --name scwrypts/environment/synchronize --group scwrypts --type zsh -- --no-prompt \ && SUCCESS "created '$ENV_FILE'" \
&& SUCCESS "created '$ENV_NAME'" \ || FAIL 2 "something went wrong creating '$ENV_FILE'"
|| FAIL 3 "something went wrong creating '$ENV_NAME'" done
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)' \
;

View File

@ -11,18 +11,26 @@ PROMPT 'choose an environment to delete'
ENV_NAME=$(SCWRYPTS__SELECT_ENV) ENV_NAME=$(SCWRYPTS__SELECT_ENV)
[ ! $ENV_NAME ] && ABORT [ ! $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'" STATUS "preparing to remove '$ENV_NAME'"
WARNING " WARNING "
the '$ENV_NAME' environment will be removed the '$ENV_NAME' environment will be removed configured options
configured options and stored credentials will be lost forever and stored credentials will be lost forever:
$(echo $ENV_FILES | sed 's| /|\n - /|g; s/^/ - /')
" "
yN 'continue?' || ABORT yN 'continue?' || ABORT
STATUS "removing environment" STATUS "removing environment"
for ENV_FILE in ${ENV_FILES[@]}
do
rm "$ENV_FILE" \ rm "$ENV_FILE" \
&& SUCCESS "removed '$ENV_NAME'" \ && SUCCESS "removed '$ENV_FILE'" \
|| FAIL 3 "unable to remove '$ENV_FILE'; is it protected?" || ERROR "unable to remove '$ENV_FILE'; is it protected?" \
;
done
CHECK_ERRORS -n || FAIL 2 "some errors ocurred when cleaning up $ENV_NAME"

View File

@ -16,16 +16,26 @@ CHECK_ENVIRONMENT
} }
[ ! $ENV_NAME ] && ABORT [ ! $ENV_NAME ] && ABORT
ENV_FILE=$(SCWRYPTS__GET_ENV_FILE $ENV_NAME 2>/dev/null) ENV_FILES=($(SCWRYPTS__GET_ENV_FILES $ENV_NAME 2>/dev/null))
for ENV_FILE in ${ENV_FILES[@]}
do
[ ! -f "$ENV_FILE" ] && { [ ! -f "$ENV_FILE" ] && {
STATUS "Creating '$ENV_NAME'..." \ STATUS "Creating '$ENV_FILE'..." \
&& touch "$ENV_FILE" \ && touch "$ENV_FILE" \
&& SCWRYPTS__RUN --name scwrypts/environment/synchronize --group scwrypts --type zsh -- --no-prompt \ && ((CREATED+=1)) \
&& SUCCESS "created '$ENV_NAME'" \ && SUCCESS "created '$ENV_NAME'" \
|| { ERROR "failed to create '$ENV_FILE'"; exit 1; } || { 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 \ SCWRYPTS__RUN --name scwrypts/environment/synchronize --group scwrypts --type zsh -- --no-prompt \
|| FAIL 4 'failed to run environment sync' \ || FAIL 4 'failed to run environment sync' \

View File

@ -1,8 +0,0 @@
#!/bin/zsh
DEPENDENCIES+=()
REQUIRED_ENV+=()
CHECK_ENVIRONMENT
#####################################################################
__CHECK_REQUIRED_ENV $@

View File

@ -49,11 +49,15 @@ SYNCHRONIZE() {
local ENVIRONMENTS ENVIRONMENT_FILES local ENVIRONMENTS ENVIRONMENT_FILES
local FILE NAME ENVIRONMENT_FILE local FILE NAME ENVIRONMENT_FILE
GROUP_PIDS=()
for GROUP in ${SCWRYPTS_GROUPS}
do
{
ENVIRONMENTS=($(SCWRYPTS__GET_ENV_NAMES | sort -r)) ENVIRONMENTS=($(SCWRYPTS__GET_ENV_NAMES | sort -r))
ENVIRONMENT_FILES=($( ENVIRONMENT_FILES=($(
for NAME in ${ENVIRONMENTS[@]} for NAME in ${ENVIRONMENTS[@]}
do do
SCWRYPTS__GET_ENV_FILE $NAME SCWRYPTS__GET_ENV_FILE $NAME $GROUP
done done
)) ))
@ -75,13 +79,17 @@ SYNCHRONIZE() {
CLEANUP_ENVIRONMENT_FILE "$FILE" CLEANUP_ENVIRONMENT_FILE "$FILE"
done done
SUCCESS 'finished sync!' SUCCESS 'finished sync!'
} &
GROUP_PIDS+=$!
done
for P in ${GROUP_PIDS[@]}; do wait $P; done
} }
##################################################################### #####################################################################
CASCADE_ENVIRONMENT() { CASCADE_ENVIRONMENT() {
local PARENT_NAME="$1" 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\\.")) local CHILD_NAMES=($(echo $ENVIRONMENTS | sed 's/ \+/\n/g' |grep "^$PARENT_NAME\\."))
[[ ${#CHILD_NAMES[@]} -eq 0 ]] && return 0 [[ ${#CHILD_NAMES[@]} -eq 0 ]] && return 0
@ -93,7 +101,7 @@ CASCADE_ENVIRONMENT() {
for CHILD_NAME in ${CHILD_NAMES[@]} for CHILD_NAME in ${CHILD_NAMES[@]}
do do
STATUS "propagating environment '$PARENT_NAME' to child '$CHILD_NAME'" 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") CONTENT=$(cat "$CHILD_FILE")
echo "$PARENT_VARIABLES" | ADD_LINES echo "$PARENT_VARIABLES" | ADD_LINES
echo "$CONTENT" > "$CHILD_FILE" echo "$CONTENT" > "$CHILD_FILE"

View File

@ -25,6 +25,9 @@ LAUNCH_OR_SHOW() {
-a, --always-launch invoke executable even if client-class exists -a, --always-launch invoke executable even if client-class exists
-n, --no-resize don't resize the window (ignores -sxy flags) -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 -h, --help print this message and exit
@ -47,6 +50,8 @@ LAUNCH_OR_SHOW() {
local ALWAYS_LAUNCH=0 local ALWAYS_LAUNCH=0
local RESIZE=1 local RESIZE=1
local MOVE=1
local MIN_ACTIVE=1
while [[ $# -gt 0 ]] while [[ $# -gt 0 ]]
do do
@ -58,6 +63,9 @@ LAUNCH_OR_SHOW() {
-a | --always-launch ) ALWAYS_LAUNCH=1 ;; -a | --always-launch ) ALWAYS_LAUNCH=1 ;;
-n | --no-resize ) RESIZE=0 ;; -n | --no-resize ) RESIZE=0 ;;
-l | --no-center ) MOVE=0 ;;
--has-statusbar-icon ) MIN_ACTIVE=2 ;;
-h | --help ) USAGE; exit 0 ;; -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 local LAUNCH_APP=$ALWAYS_LAUNCH
STATUS "looking for window process ids" STATUS "looking for window process ids"
@ -107,11 +121,15 @@ LAUNCH_OR_SHOW() {
&& STATUS 'resizing window' \ && STATUS 'resizing window' \
&& i3-msg "[class=$CLIENT_CLASS] resize set $WINDOW_SIZE" && i3-msg "[class=$CLIENT_CLASS] resize set $WINDOW_SIZE"
[[ $CURRENTLY_ACTIVE -lt $MIN_ACTIVE ]] && {
STATUS 'pulling window from scratchpad to foreground' STATUS 'pulling window from scratchpad to foreground'
i3-msg "[class=$CLIENT_CLASS] scratchpad show" i3-msg "[class=$CLIENT_CLASS] scratchpad show"
}
STATUS 'moving window to center of current screen' 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
} }
##################################################################### #####################################################################

View File

@ -65,7 +65,7 @@ INSTALL() {
} }
} }
ERROR_CHECK CHECK_ERRORS
#################################################### ####################################################