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
This commit is contained in:
parent
6c546ebb6f
commit
4baacd9c32
7
run
7
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
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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() {
|
||||
|
@ -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,15 +85,15 @@ SCWRYPTS__INIT_ENVIRONMENTS() {
|
||||
_SED() { sed --follow-symlinks $@; }
|
||||
|
||||
GENERATE_TEMPLATE() {
|
||||
echo "#!/bin/zsh"
|
||||
echo '#####################################################################'
|
||||
echo "### scwrypts runtime configuration ##################################"
|
||||
echo '#####################################################################'
|
||||
local FILE GROUP CONTENT
|
||||
[ ! $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")}}"
|
||||
|
||||
local FILE CONTENT
|
||||
local VARIABLE DESCRIPTION
|
||||
for GROUP in ${SCWRYPTS_GROUPS[@]}
|
||||
do
|
||||
FILE=$(eval echo '$SCWRYPTS_ENV_TEMPLATE__'$GROUP)
|
||||
FILE=$(eval echo '$SCWRYPTS_ROOT__'$GROUP/.config/env.template)
|
||||
|
||||
CONTENT=$(GET_VARIABLE_NAMES "$FILE" | sed 's/^/export /; s/$/=/')
|
||||
|
||||
@ -80,8 +107,6 @@ GENERATE_TEMPLATE() {
|
||||
done < <(_SED -n '/^[^ ]\+ \+| /p' "$FILE.descriptions")
|
||||
|
||||
echo "$CONTENT" | sed 's/^#$//'
|
||||
echo '\n#####################################################################'
|
||||
done
|
||||
}
|
||||
|
||||
GET_VARIABLE_NAMES() {
|
||||
@ -91,4 +116,3 @@ GET_VARIABLE_NAMES() {
|
||||
| grep -v '__[a-z]\+$' \
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
||||
[ -f "$ENV_FILE" ] && FAIL 2 "'$ENV_NAME' already exists"
|
||||
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)
|
||||
|
||||
STATUS "creating environment '$ENV_NAME'"
|
||||
cat "$TEMPLATE_ENV_FILE" \
|
||||
| sed 's/ from.*//' \
|
||||
| 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 "created '$ENV_FILE'" \
|
||||
|| FAIL 2 "something went wrong creating '$ENV_FILE'"
|
||||
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)' \
|
||||
;
|
||||
|
@ -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"
|
||||
for ENV_FILE in ${ENV_FILES[@]}
|
||||
do
|
||||
rm "$ENV_FILE" \
|
||||
&& SUCCESS "removed '$ENV_NAME'" \
|
||||
|| FAIL 3 "unable to remove '$ENV_FILE'; is it protected?"
|
||||
&& 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"
|
||||
|
@ -16,16 +16,26 @@ CHECK_ENVIRONMENT
|
||||
}
|
||||
[ ! $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" ] && {
|
||||
STATUS "Creating '$ENV_NAME'..." \
|
||||
STATUS "Creating '$ENV_FILE'..." \
|
||||
&& touch "$ENV_FILE" \
|
||||
&& SCWRYPTS__RUN --name scwrypts/environment/synchronize --group scwrypts --type zsh -- --no-prompt \
|
||||
&& ((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' \
|
||||
|
@ -1,8 +0,0 @@
|
||||
#!/bin/zsh
|
||||
DEPENDENCIES+=()
|
||||
REQUIRED_ENV+=()
|
||||
|
||||
CHECK_ENVIRONMENT
|
||||
#####################################################################
|
||||
|
||||
__CHECK_REQUIRED_ENV $@
|
@ -49,11 +49,15 @@ SYNCHRONIZE() {
|
||||
local ENVIRONMENTS ENVIRONMENT_FILES
|
||||
local FILE NAME ENVIRONMENT_FILE
|
||||
|
||||
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
|
||||
SCWRYPTS__GET_ENV_FILE $NAME $GROUP
|
||||
done
|
||||
))
|
||||
|
||||
@ -75,13 +79,17 @@ SYNCHRONIZE() {
|
||||
CLEANUP_ENVIRONMENT_FILE "$FILE"
|
||||
done
|
||||
SUCCESS 'finished sync!'
|
||||
} &
|
||||
GROUP_PIDS+=$!
|
||||
done
|
||||
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"
|
||||
|
@ -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"
|
||||
|
||||
[[ $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
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
|
@ -65,7 +65,7 @@ INSTALL() {
|
||||
}
|
||||
}
|
||||
|
||||
ERROR_CHECK
|
||||
CHECK_ERRORS
|
||||
|
||||
####################################################
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user