Compare commits

..

1 Commits

Author SHA1 Message Date
d1a17e4285 v4.3.0
=====================================================================

--- Changes ------------------------------

- updated python scwrypts API to use latest pattern established in the
  nodejs library

- SCWRYPTS_ROOT__scwrypts is now supports loading with each run and
  detects managed installations vs manual installations; this now means
  SCWRYPTS_ROOT can no longer be injected to scwrypts (this was a v2
  legacy support thing and probably does not apply to you)

--- New Features -------------------------

- pypi/scwrypts )
     added 'get_generator' API to testing utilities to provide a nice
     way to include default generator options

--- Bug Fixes ----------------------------

- scwrypts groups which use a required environment name regex no longer
  load specialized static files outside of the required environments.
2024-04-16 08:52:47 -06:00
17 changed files with 159 additions and 391 deletions

View File

@ -52,13 +52,6 @@ custom:
useradd -m ci useradd -m ci
echo "ci ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers echo "ci ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
temp-downgrade-fakeroot:
- &archlinux-temp-downgrade-fakeroot
run:
name: downgrade fakeroot to v1.34 (v1.35 and v1.36 are confirmed to break)
command: |
pacman -U --noconfirm https://archive.archlinux.org/packages/f/fakeroot/fakeroot-1.34-1-x86_64.pkg.tar.zst
clone-aur: clone-aur:
- &archlinux-clone-aur - &archlinux-clone-aur
archlinux-run: archlinux-run:
@ -91,7 +84,6 @@ jobs:
executor: archlinux executor: archlinux
steps: steps:
- *archlinux-prepare - *archlinux-prepare
- *archlinux-temp-downgrade-fakeroot
- *archlinux-clone-aur - *archlinux-clone-aur
- *archlinux-clone-scwrypts - *archlinux-clone-scwrypts
- archlinux-run: - archlinux-run:
@ -110,7 +102,6 @@ jobs:
&& echo "source=(scwrypts.tar.gz)" >> PKGBUILD && echo "source=(scwrypts.tar.gz)" >> PKGBUILD
&& echo "sha256sums=(SKIP)" >> PKGBUILD && echo "sha256sums=(SKIP)" >> PKGBUILD
&& makepkg --noconfirm -si && makepkg --noconfirm -si
&& echo validating scwrypts version
&& scwrypts --version | grep "^scwrypts v$PKGVER$" && scwrypts --version | grep "^scwrypts v$PKGVER$"
; ;
@ -118,7 +109,6 @@ jobs:
executor: archlinux executor: archlinux
steps: steps:
- *archlinux-prepare - *archlinux-prepare
- *archlinux-temp-downgrade-fakeroot
- *archlinux-clone-aur - *archlinux-clone-aur
- archlinux-run: - archlinux-run:
_name: update PKGBUILD and .SRCINFO _name: update PKGBUILD and .SRCINFO

View File

@ -12,9 +12,13 @@ export DISCORD__DEFAULT_AVATAR_URL=
export DISCORD__DEFAULT_CHANNEL_ID= export DISCORD__DEFAULT_CHANNEL_ID=
export DISCORD__DEFAULT_USERNAME= export DISCORD__DEFAULT_USERNAME=
export DISCORD__DEFAULT_WEBHOOK= export DISCORD__DEFAULT_WEBHOOK=
export I3__BORDER_PIXEL_SIZE=
export I3__DMENU_FONT_SIZE=
export I3__GLOBAL_FONT_SIZE=
export I3__MODEL_CONFIG=
export LINEAR__API_TOKEN= export LINEAR__API_TOKEN=
export MEDIA_SYNC__S3_BUCKET= export MEDIA_SYNC__S3_BUCKET
export MEDIA_SYNC__TARGETS= export MEDIA_SYNC__TARGETS
export REDIS_AUTH= export REDIS_AUTH=
export REDIS_HOST= export REDIS_HOST=
export REDIS_PORT= export REDIS_PORT=

View File

@ -15,6 +15,11 @@ DISCORD__DEFAULT_CHANNEL_ID |
DISCORD__DEFAULT_USERNAME | DISCORD__DEFAULT_USERNAME |
DISCORD__DEFAULT_WEBHOOK | DISCORD__DEFAULT_WEBHOOK |
I3__BORDER_PIXEL_SIZE | custom i3 configuration settings
I3__DMENU_FONT_SIZE |
I3__GLOBAL_FONT_SIZE |
I3__MODEL_CONFIG |
LINEAR__API_TOKEN | linear.app project management configuration LINEAR__API_TOKEN | linear.app project management configuration
MEDIA_SYNC__S3_BUCKET | s3 bucket name and filesystem targets for media backups MEDIA_SYNC__S3_BUCKET | s3 bucket name and filesystem targets for media backups

View File

@ -1,10 +1,11 @@
[[ $SCWRYPTS_KUBECTL_DRIVER_READY -eq 1 ]] && return 0 [[ $SCWRYPTS_KUBECTL_DRIVER_READY -eq 1 ]] && return 0
unalias k h f >/dev/null 2>&1 unalias k h >/dev/null 2>&1
k() { _SCWRYPTS_KUBECTL_DRIVER kubectl $@; } k() { _SCWRYPTS_KUBECTL_DRIVER kubectl $@; }
h() { _SCWRYPTS_KUBECTL_DRIVER helm $@; } h() { _SCWRYPTS_KUBECTL_DRIVER helm $@; }
f() { _SCWRYPTS_KUBECTL_DRIVER flux $@; } f() { _SCWRYPTS_KUBECTL_DRIVER flux $@; }
_SCWRYPTS_KUBECTL_DRIVER() { _SCWRYPTS_KUBECTL_DRIVER() {
[ ! $SCWRYPTS_ENV ] && { [ ! $SCWRYPTS_ENV ] && {
ERROR "must set SCWRYPTS_ENV in order to use '$(echo $CLI | head -c1)'" ERROR "must set SCWRYPTS_ENV in order to use '$(echo $CLI | head -c1)'"

View File

@ -4,7 +4,7 @@ from .scwrypts.exceptions import MissingVariableError
def getenv(name, required=True): def getenv(name, required=True):
value = os_getenv(f'{name}__override', os_getenv(name)) value = os_getenv(name, None)
if required and not value: if required and not value:
raise MissingVariableError(name) raise MissingVariableError(name)

137
scwrypts
View File

@ -1,6 +1,5 @@
#!/bin/zsh #!/bin/zsh
export EXECUTION_DIR=$(pwd) export EXECUTION_DIR=$(pwd)
export SCWRYPTS_RUNTIME_ID=$(uuidgen)
source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42 source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
##################################################################### #####################################################################
() { () {
@ -22,26 +21,21 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
runtime runtime
-y, --yes auto-accept all [yn] prompts through current scwrypt -y, --yes auto-accept all [yn] prompts through current scwrypt
-e, --env <env-name> set environment; overwrites SCWRYPTS_ENV -e, --env <env-name> set environment; overwrites SCWRYPTS_ENV
-n shorthand for "--log-level 0"
-n shorthand for "--log-level 0" -v, --log-level [0-4] set incremental scwrypts log level to one of the following:
-v, --log-level <0-4> set incremental scwrypts log level to one of the following: 0 : only command output and critical failures; skips logfile
0 : only command output and critical failures; skips logfile 1 : include success / failure messages
1 : include success / failure messages 2 : include status update messages
2 : include status update messages 3 : (default) include warning messages
3 : (default) include warning messages 4 : include debug messages
4 : include debug messages
-o, --output <format> specify output format; one of: pretty,json (default: pretty)
alternate commands alternate commands
-h, --help display this message and exit -h, --help display this message and exit
-l, --list print out command list and exit -l, --list print out command list and exit
--list-envs print out environment list and exit --list-envs print out environment list and exit
--list-groups print out configured scwrypts groups and exit --root print out SCWRYPTS_ROOT__scwrypts and exit
--config "eval"-ed to enable config and "use" import in non-scwrypts environments --update update scwrypts library to latest version
--root print out SCWRYPTS_ROOT__scwrypts and exit --version print out scwrypts version and exit
--update update scwrypts library to latest version
--version print out scwrypts version and exit
patterns: patterns:
- a list of glob patterns to loose-match a scwrypt by name - a list of glob patterns to loose-match a scwrypt by name
@ -62,10 +56,8 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
[ ! $SCWRYPTS_LOG_LEVEL ] && local SCWRYPTS_LOG_LEVEL=3 [ ! $SCWRYPTS_LOG_LEVEL ] && local SCWRYPTS_LOG_LEVEL=3
local SHIFT_COUNT
while [[ $# -gt 0 ]] while [[ $# -gt 0 ]]
do do
SHIFT_COUNT=1
case $1 in case $1 in
-[a-z][a-z]* ) -[a-z][a-z]* )
VARSPLIT=$(echo "$1 " | sed 's/^\(-.\)\(.*\) /\1 -\2/') VARSPLIT=$(echo "$1 " | sed 's/^\(-.\)\(.*\) /\1 -\2/')
@ -89,15 +81,10 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
return 0 return 0
;; ;;
--list-groups )
echo "${SCWRYPTS_GROUPS[@]}" | sed 's/\s\+/\n/g' | sort -u
return 0
;;
--version ) --version )
case $SCWRYPTS_INSTALLATION_TYPE in case $SCWRYPTS_INSTALLATION_TYPE in
manual ) echo "scwrypts $(GIT_SCWRYPTS describe --tags) (via GIT)" ;; manual ) echo "scwrypts $(GIT_SCWRYPTS describe --tags) (via GIT)" ;;
* ) echo "scwrypts $(cat "$SCWRYPTS_ROOT__scwrypts/VERSION")" ;; * ) echo scwrypts $(cat "$SCWRYPTS_ROOT__scwrypts/VERSION") ;;
esac esac
return 0 return 0
;; ;;
@ -107,13 +94,6 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
return 0 return 0
;; ;;
--config )
echo "source '$SCWRYPTS_ROOT__scwrypts/zsh/lib/import.driver.zsh'"
echo "CHECK_ENVIRONMENT --no-fail --no-usage"
echo "unset __SCWRYPT"
return 0
;;
--update ) --update )
case $SCWRYPTS_INSTALLATION_TYPE in case $SCWRYPTS_INSTALLATION_TYPE in
aur ) aur )
@ -124,7 +104,7 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
;; ;;
homebrew ) homebrew )
SCWRYPTS_LOG_LEVEL=3 REMINDER "This installation is managed by homebrew. Update me with 'brew update'" SCWRYPTS_LOG_LEVEL=3 REMINDER "This installation is managed by homebrew. Update me with 'brew update scwrypts'"
;; ;;
manual ) manual )
@ -162,54 +142,46 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
### scwrypts filters ##################### ### scwrypts filters #####################
-m | --name ) -m | --name )
((SHIFT_COUNT+=1))
[ $2 ] || { ERROR "missing value for argument $1"; break; } [ $2 ] || { ERROR "missing value for argument $1"; break; }
SEARCH_NAME=$2 SEARCH_NAME=$2
shift 1
;; ;;
-g | --group ) -g | --group )
((SHIFT_COUNT+=1))
[ $2 ] || { ERROR "missing value for argument $1"; break; } [ $2 ] || { ERROR "missing value for argument $1"; break; }
SEARCH_GROUP=$2 SEARCH_GROUP=$2
GROUP=$2 shift 1
;; ;;
-t | --type ) -t | --type )
((SHIFT_COUNT+=1))
[ $2 ] || { ERROR "missing value for argument $1"; break; } [ $2 ] || { ERROR "missing value for argument $1"; break; }
SEARCH_TYPE=$2 SEARCH_TYPE=$2
TYPE=$2 shift 1
;; ;;
### runtime settings ##################### ### runtime settings #####################
-y | --yes ) export __SCWRYPTS_YES=1 ;; -y | --yes ) export __SCWRYPTS_YES=1 ;;
-n ) SCWRYPTS_LOG_LEVEL=0 ;; -n | --no-log )
SCWRYPTS_LOG_LEVEL=0
-v | --log-level ) [[ $1 =~ ^--no-log$ ]] && WARNING 'the --no-log flag is deprecated and will be removed in scwrypts v4.2'
((SHIFT_COUNT+=1))
[[ $2 =~ ^[0-4]$ ]] || ERROR "invalid setting for log-level '$2'"
SCWRYPTS_LOG_LEVEL=$2
;; ;;
-o | --output ) -v | --log-level )
((SHIFT_COUNT+=1)) [[ $2 =~ ^[0-4]$ ]] || ERROR "invalid setting for log-level '$2'"
export SCWRYPTS_OUTPUT_FORMAT=$2 SCWRYPTS_LOG_LEVEL=$2
case $SCWRYPTS_OUTPUT_FORMAT in shift 1
pretty | json ) ;;
* ) ERROR "unsupported format '$SCWRYPTS_OUTPUT_FORMAT'" ;;
esac
;; ;;
-e | --env ) -e | --env )
((SHIFT_COUNT+=1))
[ $2 ] || { ERROR "missing value for argument $1"; break; } [ $2 ] || { ERROR "missing value for argument $1"; break; }
[ $ENV_NAME ] && DEBUG 'overwriting session environment' [ $ENV_NAME ] && DEBUG 'overwriting session environment'
ENV_NAME="$2" ENV_NAME="$2"
STATUS "using CLI environment '$ENV_NAME'" STATUS "using CLI environment '$ENV_NAME'"
shift 1
;; ;;
########################################## ##########################################
@ -218,11 +190,9 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
--* ) ERROR "unrecognized argument '$1'" ;; --* ) ERROR "unrecognized argument '$1'" ;;
* ) SEARCH_PATTERNS+=($1) ;; * ) SEARCH_PATTERNS+=($1) ;;
esac esac
shift $SHIFT_COUNT shift 1
done done
[ $SCWRYPTS_OUTPUT_FORMAT ] || export SCWRYPTS_OUTPUT_FORMAT=pretty
[ $SEARCH_NAME ] && { [ $SEARCH_NAME ] && {
[ $SEARCH_TYPE ] || ERROR '--name requires --type argument' [ $SEARCH_TYPE ] || ERROR '--name requires --type argument'
[ $SEARCH_GROUP ] || ERROR '--name requires --group argument' [ $SEARCH_GROUP ] || ERROR '--name requires --group argument'
@ -249,6 +219,7 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
echo $SCWRYPTS_AVAILABLE | head -n1 echo $SCWRYPTS_AVAILABLE | head -n1
echo $SCWRYPTS_AVAILABLE | grep ' [^/]*'$SEARCH_TYPE'[^/]* ' echo $SCWRYPTS_AVAILABLE | grep ' [^/]*'$SEARCH_TYPE'[^/]* '
} \ } \
| awk '{$2=""; print $0;}' \
| sed 's/ \+$/'$(printf $__COLOR_RESET)'/; s/ \+/^/g' \ | sed 's/ \+$/'$(printf $__COLOR_RESET)'/; s/ \+/^/g' \
| column -ts '^' | column -ts '^'
) )
@ -258,8 +229,9 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
SCWRYPTS_AVAILABLE=$( SCWRYPTS_AVAILABLE=$(
{ {
echo $SCWRYPTS_AVAILABLE | head -n1 echo $SCWRYPTS_AVAILABLE | head -n1
echo $SCWRYPTS_AVAILABLE | grep "$SEARCH_GROUP"'[^/ ]*$' echo $SCWRYPTS_AVAILABLE | grep "$SEARCH_GROUP"'[^/]*$'
} \ } \
| awk '{$NF=""; print $0;}' \
| sed 's/ \+$/'$(printf $__COLOR_RESET)'/; s/ \+/^/g' \ | sed 's/ \+$/'$(printf $__COLOR_RESET)'/; s/ \+/^/g' \
| column -ts '^' | column -ts '^'
) )
@ -412,42 +384,25 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
[[ $SCWRYPT_NAME =~ interactive ]] && RUN_MODE=interactive [[ $SCWRYPT_NAME =~ interactive ]] && RUN_MODE=interactive
local HEADER FOOTER local HEADER FOOTER
[[ $SCWRYPTS_LOG_LEVEL -ge 2 ]] && {
case $SCWRYPTS_OUTPUT_FORMAT in
pretty )
HEADER=$(
echo "
=====================================================================
scwrypt : $SCWRYPT_GROUP $SCWRYPT_TYPE $SCWRYPT_NAME
run at : $(date)
config : $ENV_NAME
log level : $SCWRYPTS_LOG_LEVEL
\\033[1;33m--- SCWRYPT BEGIN ---------------------------------------------------\\033[0m
" | sed 's/^\s\+//; 1d'
)
FOOTER="\\033[1;33m--- SCWRYPT END ---------------------------------------------------\\033[0m" [[ $SCWRYPTS_LOG_LEVEL -ge 2 ]] && {
;; HEADER=$(
json ) echo "
HEADER=$(echo '{}' | jq -c ". =====================================================================
| .timestamp = \"$(date +%s)\" script : $SCWRYPT_GROUP $SCWRYPT_TYPE $SCWRYPT_NAME
| .runtime = \"$SCWRYPTS_RUNTIME_ID\" run at : $(date)
| .scwrypt = \"start of $SCWRYPT_NAME $SCWRYPT_GROUP $SCWRYPT_TYPE\" config : $ENV_NAME
| .config = \"$ENV_NAME\" log level : $SCWRYPTS_LOG_LEVEL
| .logLevel = \"$SCWRYPTS_LOG_LEVEL\" \\033[1;33m--- SCWRYPT BEGIN ---------------------------------------------------\\033[0m
| .subscwrypt = $SUBSCWRYPT " | sed 's/^\s\+//; 1d'
") )
;;
esac FOOTER="\\033[1;33m--- SCWRYPT END ---------------------------------------------------\\033[0m"
} }
[[ $SUBSCWRYPT -eq 0 ]] || { [[ $SUBSCWRYPT -eq 0 ]] || {
case $SCWRYPTS_OUTPUT_FORMAT in HEADER="\\033[0;33m--- ($SUBSCWRYPT) BEGIN $SCWRYPT_GROUP $SCWRYPT_TYPE $SCWRYPT_NAME ---"
pretty ) FOOTER="\\033[0;33m--- ($SUBSCWRYPT) END $SCWRYPT_GROUP $SCWRYPT_TYPE $SCWRYPT_NAME ---"
HEADER="\\033[0;33m--- ($SUBSCWRYPT) BEGIN $SCWRYPT_GROUP $SCWRYPT_TYPE $SCWRYPT_NAME ---"
FOOTER="\\033[0;33m--- ($SUBSCWRYPT) END $SCWRYPT_GROUP $SCWRYPT_TYPE $SCWRYPT_NAME ---"
;;
esac
} }
##################################################################### #####################################################################
@ -478,5 +433,5 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
&& echo "terminated with\\033[1;$EXIT_COLOR code $EXIT_CODE\\033[0m" && echo "terminated with\\033[1;$EXIT_COLOR code $EXIT_CODE\\033[0m"
return $EXIT_CODE return $EXIT_CODE
} | tee --append "$LOGFILE" } 2>&1 | tee --append "$LOGFILE"
} $@ } $@

View File

@ -1,223 +1,82 @@
#
# typically you do not need to reload this plugin in a single session;
# if for some reason you do, you can run the following command and
# source this file again
#
# unset __SCWRYPTS_PLUGIN_LOADED
#
[[ $__SCWRYPTS_PLUGIN_LOADED =~ true ]] && return 0
##################################################################### #####################################################################
: \ : \
&& command -v scwrypts &>/dev/null \ && command -v scwrypts &>/dev/null \
&& eval "$(scwrypts --config)" \ && source "$(scwrypts --root)/zsh/lib/import.driver.zsh" \
&& unset __SCWRYPT \
|| { || {
echo 'scwrypts must be in PATH and properly configured; skipping zsh plugin setup' >&2 echo 'scwrypts must be in PATH and properly configured; skipping zsh plugin setup' >&2
return 0 return 0
} }
__SCWRYPTS_PARSE() { #####################################################################
SCWRYPT_SELECTION=$(scwrypts --list | fzf --ansi --prompt 'select a script : ' --header-lines 1)
SCWRYPTS__ZSH_PLUGIN() {
local SCWRYPT_SELECTION=$(scwrypts --list | FZF 'select a script' --header-lines 1)
local NAME
local TYPE
local GROUP
LBUFFER= RBUFFER= LBUFFER= RBUFFER=
[ $SCWRYPT_SELECTION ] || return 1 [ ! $SCWRYPT_SELECTION ] && { zle accept-line; return 0; }
NAME=$(echo "$SCWRYPT_SELECTION" | awk '{print $1;}') SCWRYPTS__SEPARATE_SCWRYPT_SELECTION $SCWRYPT_SELECTION
TYPE=$(echo "$SCWRYPT_SELECTION" | awk '{print $2;}')
GROUP=$(echo "$SCWRYPT_SELECTION" | awk '{print $3;}')
[ $NAME ] && [ $TYPE ] && [ $GROUP ] which scwrypts >/dev/null 2>&1\
&& RBUFFER="scwrypts" || RBUFFER="$SCWRYPTS_ROOT/scwrypts"
RBUFFER+=" --name $NAME --group $GROUP --type $TYPE"
zle accept-line
} }
zle -N scwrypts SCWRYPTS__ZSH_PLUGIN
bindkey $SCWRYPTS_SHORTCUT scwrypts
##################################################################### #####################################################################
[ $SCWRYPTS_SHORTCUT ] && { SCWRYPTS__ZSH_BUILDER_PLUGIN() {
SCWRYPTS__ZSH_PLUGIN() { local SCWRYPT_SELECTION=$(scwrypts --list | FZF 'select a script' --header-lines 1)
local SCWRYPT_SELECTION NAME TYPE GROUP echo $SCWRYPT_SELECTION >&2
__SCWRYPTS_PARSE || { zle accept-line; return 0; } local NAME
local TYPE
local GROUP
LBUFFER= RBUFFER=
[ ! $SCWRYPT_SELECTION ] && { zle accept-line; return 0; }
RBUFFER="scwrypts --name $NAME --type $TYPE --group $GROUP" SCWRYPTS__SEPARATE_SCWRYPT_SELECTION $SCWRYPT_SELECTION
scwrypts -n --name $NAME --group $GROUP --type $TYPE -- --help >&2 || {
zle accept-line zle accept-line
return 0
} }
echo
zle -N scwrypts SCWRYPTS__ZSH_PLUGIN zle reset-prompt
bindkey $SCWRYPTS_SHORTCUT scwrypts which scwrypts >/dev/null 2>&1\
unset SCWRYPTS_SHORTCUT && LBUFFER="scwrypts" || LBUFFER="$SCWRYPTS_ROOT/scwrypts"
LBUFFER+=" --name $NAME --group $GROUP --type $TYPE -- "
} }
zle -N scwrypts-builder SCWRYPTS__ZSH_BUILDER_PLUGIN
bindkey $SCWRYPTS_BUILDER_SHORTCUT scwrypts-builder
##################################################################### #####################################################################
[ $SCWRYPTS_BUILDER_SHORTCUT ] && { SCWRYPTS__ZSH_PLUGIN_ENV() {
SCWRYPTS__ZSH_BUILDER_PLUGIN() { local RESET='reset'
local SCWRYPT_SELECTION NAME TYPE GROUP local SELECTED=$(\
__SCWRYPTS_PARSE || { echo >&2; zle accept-line; return 0; } { [ $SCWRYPTS_ENV ] && echo $RESET; SCWRYPTS__GET_ENV_NAMES; } \
echo $SCWRYPT_SELECTION >&2 | FZF 'select an environment' \
)
scwrypts -n --name $NAME --group $GROUP --type $TYPE -- --help >&2 || { zle clear-command-line
zle accept-line [ $SELECTED ] && {
return 0 [[ $SELECTED =~ ^$RESET$ ]] \
} && RBUFFER='unset SCWRYPTS_ENV' \
echo || RBUFFER="export SCWRYPTS_ENV=$SELECTED"
zle reset-prompt
LBUFFER="scwrypts --name $NAME --type $TYPE --group $GROUP -- "
} }
zle accept-line
zle -N scwrypts-builder SCWRYPTS__ZSH_BUILDER_PLUGIN
bindkey $SCWRYPTS_BUILDER_SHORTCUT scwrypts-builder
unset SCWRYPTS_BUILDER_SHORTCUT
} }
##################################################################### zle -N scwrypts-setenv SCWRYPTS__ZSH_PLUGIN_ENV
bindkey $SCWRYPTS_ENV_SHORTCUT scwrypts-setenv
[ $SCWRYPTS_ENV_SHORTCUT ] && {
SCWRYPTS__ZSH_PLUGIN_ENV() {
local RESET='reset'
local SELECTED=$(\
{ [ $SCWRYPTS_ENV ] && echo $RESET; scwrypts --list-envs; } \
| fzf --prompt 'select an environment : ' \
)
zle clear-command-line
[ $SELECTED ] && {
[[ $SELECTED =~ ^$RESET$ ]] \
&& RBUFFER='unset SCWRYPTS_ENV' \
|| RBUFFER="export SCWRYPTS_ENV=$SELECTED"
}
zle accept-line
}
zle -N scwrypts-setenv SCWRYPTS__ZSH_PLUGIN_ENV
bindkey $SCWRYPTS_ENV_SHORTCUT scwrypts-setenv
unset SCWRYPTS_ENV_SHORTCUT
}
#####################################################################
# badass(/terrifying?) zsh autocompletion
command -v compdef &>/dev/null && {
_scwrypts() {
echo $words | grep -q "\s--\s" && _arguments && return 0
eval "_arguments $(
{
HELP=$(scwrypts --help 2>&1 | sed -n 's/^\s\+\(-.* .\)/\1/p' | sed 's/[[]/(/g; s/[]]/)/g')
echo $HELP \
| sed 's/^\(\(-[^-\s]\),*\s*\|\)\(\(--[-a-z0-9A-Z\]*\)\s\(<\([^>]*\)>\|\)\|\)\s\+\(.*\)/\2[\7]:\6:->\2/' \
| grep -v '^[[]' \
;
echo $HELP \
| sed 's/^\(\(-[^-\s]\),*\s*\|\)\(\(--[-a-z0-9A-Z\]*\)\s\(<\([^>]*\)>\|\)\|\)\s\+\(.*\)/\4[\7]:\6:->\4/' \
| grep -v '^[[]' \
;
echo ":pattern:->pattern"
echo ":pattern:->pattern"
echo ":pattern:->pattern"
echo ":pattern:->pattern"
echo ":pattern:->pattern"
} | sed 's/::->.*$//g' | sed "s/\\(^\\|$\\)/'/g" | tr '\n' ' '
)"
local _group=''
echo $words | grep -q ' -g [^\s]' \
&& _group=$(echo $words | sed 's/.*-g \([^ ]\+\)\s*.*/\1/')
echo $words | grep -q ' --group .' \
&& _group=$(echo $words | sed 's/.*--group \([^ ]\+\)\s*.*/\1/')
local _type=''
echo $words | grep -q ' -t [^\s]' \
&& _type=$(echo $words | sed 's/.*-t \([^ ]\+\)\s*.*/\1/')
echo $words | grep -q ' --type .' \
&& _type=$(echo $words | sed 's/.*--type \([^ ]\+\)\s*.*/\1/')
local _name=''
echo $words | grep -q ' -m [^\s]' \
&& _name=$(echo $words | sed 's/.*-m \([^ ]\+\)\s*.*/\1/')
echo $words | grep -q ' --name .' \
&& _name=$(echo $words | sed 's/.*--name \([^ ]\+\)\s*.*/\1/')
local _pattern _patterns=()
[ ! $_name ] \
&& _patterns=($(echo "${words[@]:1}" | sed 's/\s\+/\n/g' | grep -v '^-'))
_get_remaining_scwrypts() {
[ $_name ] || local _name='[^ ]\+'
[ $_type ] || local _type='[^ ]\+'
[ $_group ] || local _group='[^ ]\+'
local remaining=$(\
scwrypts --list \
| sed "1d; s,\x1B\[[0-9;]*[a-zA-Z],,g" \
| grep "^$_name\s" \
| grep "\s$_group$" \
| grep "\s$_type\s" \
)
for _pattern in ${_patterns[@]}
do
remaining=$(echo "$remaining" | grep "$_pattern")
done
echo "$remaining"
}
case $state in
( -m | --name )
compadd $(_get_remaining_scwrypts | awk '{print $1;}' | sort -u)
;;
( -t | --type )
compadd $(_get_remaining_scwrypts | awk '{print $2;}' | sort -u)
;;
( -g | --group )
[[ $_name$_type$_group =~ ^$ ]] \
&& compadd $(scwrypts --list-groups) \
|| compadd $(_get_remaining_scwrypts | awk '{print $3;}' | sort -u) \
;;
( -e | --env )
compadd $(scwrypts --list-envs)
;;
( -v | --log-level )
local _help="$(\
scwrypts --help 2>&1 \
| sed -n '/-v, --log-level/,/^$/p' \
| sed -n 's/\s\+\([0-9]\) : \(.*\)/\1 -- \2/p' \
)"
eval "local _descriptions=($(echo "$_help" | sed "s/\\(^\|$\\)/'/g"))"
local _values=($(echo "$_help" | sed 's/ --.*//'))
compadd -d _descriptions -a _values
;;
( -o | --output )
compadd pretty json
;;
( pattern )
[[ $_name =~ ^$ ]] && {
local _remaining_scwrypts="$(_get_remaining_scwrypts)"
# stop providing suggestions if your pattern is sufficient
[[ $(echo $_remaining_scwrypts | wc -l) -le 1 ]] && return 0
local _remaining_patterns="$(echo "$_remaining_scwrypts" | sed 's/\s\+/\n/g; s|/|\n|g;' | sort -u)"
for _pattern in ${_patterns[@]}
do
_remaining_patterns="$(echo "$_remaining_patterns" | grep -v "^$_pattern$")"
done
compadd $(echo $_remaining_patterns)
}
;;
( * ) ;;
esac
}
compdef _scwrypts scwrypts
}
__SCWRYPTS_PLUGIN_LOADED=true

View File

@ -1,11 +0,0 @@
SCWRYPTS_GROUPS+=(scwrypts)
export SCWRYPTS_ROOT__scwrypts="$SCWRYPTS_ROOT"
export SCWRYPTS_COLOR__scwrypts='\033[0;32m'
#export SCWRYPTS_TYPE__scwrypts=
#export SCWRYPTS_LIBRARY_ROOT__scwrypts=
export SCWRYPTS_VIRTUALENV_PATH__scwrypts="$SCWRYPTS_DATA_PATH/virtualenv"
export SCWRYPTS_PREFERRED_PYTHON_VERSIONS__scwrypts=(3.12 3.11 3.10)
export SCWRYPTS_NODE_VERSION__scwrypts=18.0.0

10
zsh/lib/config.group.zsh Normal file
View File

@ -0,0 +1,10 @@
export SCWRYPTS_ROOT__scwrypts="$SCWRYPTS_ROOT"
export SCWRYPTS_LIBRARY_ROOT__scwrypts="$SCWRYPTS_ROOT/zsh/lib"
export SCWRYPTS_COLOR__scwrypts='\033[0;32m'
export SCWRYPTS_VIRTUALENV_PATH__scwrypts="$SCWRYPTS_DATA_PATH/virtualenv"
[ ! -d "$SCWRYPTS_VIRTUALENV_PATH__scwrypts" ] && mkdir -p "$SCWRYPTS_VIRTUALENV_PATH__scwrypts"
export SCWRYPTS_PREFERRED_PYTHON_VERSIONS__scwrypts=(3.11 3.10 3.9)
export SCWRYPTS_NODE_VERSION__scwrypts=18.0.0

View File

@ -1,31 +1,26 @@
[[ $__SCWRYPT -eq 1 ]] && return 0 [[ $__SCWRYPT -eq 1 ]] && return 0
##################################################################### #####################################################################
# Apparently MacOS puts ALL of the homebrew stuff inside of a top level git repository SCWRYPTS_ROOT="$(cd -- ${0:a:h}; git rev-parse --show-toplevel 2>/dev/null)"
# with bizarre git ignores; so:
# - USE the git root if it's a manual install...
# - UNLESS that git root is just the $(brew --prefix)
SCWRYPTS_ROOT="$(cd -- ${0:a:h}; git rev-parse --show-toplevel 2>/dev/null | grep -v "^$(brew --prefix 2>/dev/null)$")"
[ $SCWRYPTS_ROOT ] && [ -d "$SCWRYPTS_ROOT" ] \ [ $SCWRYPTS_ROOT ] && [ -d "$SCWRYPTS_ROOT" ] \
|| SCWRYPTS_ROOT="$(echo "${0:a:h}" | sed -n 's|\(share/scwrypts\).*$|\1|p')" || SCWRYPTS_ROOT="echo \"${0:a:h}\" | sed -n 's|\(share/scwrypts\).*$|\1|p'"
[ $SCWRYPTS_ROOT ] && [ -d "$SCWRYPTS_ROOT" ] || { [ $SCWRYPTS_ROOT ] && [ -d "$SCWRYPTS_ROOT" ] || {
echo "cannot determine scwrypts root path for current installation; aborting" echo "cannot determine scwrypts root path for current installation; aborting"
exit 1 exit 1
} }
export SCWRYPTS_ROOT__scwrypts="$SCWRYPTS_ROOT"
[ -f "$SCWRYPTS_ROOT__scwrypts/MANAGED_BY" ] \ [ -f "$SCWRYPTS_ROOT__scwrypts/MANAGED_BY" ] \
&& export SCWRYPTS_INSTALLATION_TYPE=$(cat "$SCWRYPTS_ROOT__scwrypts/MANAGED_BY") \ && export SCWRYPTS_INSTALLATION_TYPE=$(cat "$SCWRYPTS_ROOT__scwrypts/MANAGED_BY") \
|| export SCWRYPTS_INSTALLATION_TYPE=manual \ || export SCWRYPTS_INSTALLATION_TYPE=manual \
; ;
export SCWRYPTS_ROOT__scwrypts="$SCWRYPTS_ROOT"
##################################################################### #####################################################################
DEFAULT_CONFIG="$SCWRYPTS_ROOT__scwrypts/zsh/lib/config.user.zsh" DEFAULT_CONFIG="$SCWRYPTS_ROOT/zsh/lib/config.user.zsh"
source "$DEFAULT_CONFIG" source "$DEFAULT_CONFIG"
USER_CONFIG_OVERRIDES="$SCWRYPTS_CONFIG_PATH/config.zsh" USER_CONFIG_OVERRIDES="$SCWRYPTS_CONFIG_PATH/config.zsh"
@ -53,9 +48,10 @@ export \
SCWRYPTS_OUTPUT_PATH \ SCWRYPTS_OUTPUT_PATH \
; ;
source "$SCWRYPTS_ROOT/scwrypts.scwrypts.zsh" \ SCWRYPTS_GROUPS=(scwrypts $(echo $SCWRYPTS_GROUPS | sed 's/\s\+/\n/g' | sort -u))
|| FAIL 69 'failed to set up scwrypts group; aborting'
source "$SCWRYPTS_ROOT/zsh/lib/config.group.zsh" \
|| FAIL 69 'failed to set up scwrypts group; aborting'
##################################################################### #####################################################################
@ -87,9 +83,5 @@ done
done done
} }
#####################################################################
SCWRYPTS_GROUPS=(scwrypts $(echo $SCWRYPTS_GROUPS | sed 's/\s\+/\n/g' | sort -u | grep -v '^scwrypts$'))
##################################################################### #####################################################################
__SCWRYPT=1 # arbitrary; indicates currently inside a scwrypt __SCWRYPT=1 # arbitrary; indicates currently inside a scwrypt

View File

@ -34,7 +34,7 @@ source "${0:a:h}/config.zsh"
use() { use() {
local SCWRYPTS_LIBRARY SCWRYPTS_LIBRARY_ROOT SCWRYPTS_LIBRARY_GROUP local SCWRYPTS_LIBRARY SCWRYPTS_LIBRARY_ROOT SCWRYPTS_LIBRARY_GROUP
local DEFER_ENVIRONMENT_CHECK=true local DEFER_ENVIRONMENT_CHECK=1
while [[ $# -gt 0 ]] while [[ $# -gt 0 ]]
do do
@ -49,8 +49,8 @@ use() {
SCWRYPTS_LIBRARY_ROOT=$2 SCWRYPTS_LIBRARY_ROOT=$2
shift 1 shift 1
;; ;;
-c | --check-environment ) --check-environment )
DEFER_ENVIRONMENT_CHECK=false DEFER_ENVIRONMENT_CHECK=0
;; ;;
* ) * )
[ ! $SCWRYPTS_LIBRARY ] \ [ ! $SCWRYPTS_LIBRARY ] \
@ -106,7 +106,7 @@ use() {
return 1 return 1
} }
[[ $DEFER_ENVIRONMENT_CHECK =~ false ]] && { [[ $DEFER_ENVIRONMENT_CHECK -eq 0 ]] && {
CHECK_ENVIRONMENT || { CHECK_ENVIRONMENT || {
((IMPORT_ERRORS+=1)) ((IMPORT_ERRORS+=1))
ERROR "import error for '$SCWRYPTS_LIBRARY_GROUP/$SCWRYPTS_LIBRARY'" ERROR "import error for '$SCWRYPTS_LIBRARY_GROUP/$SCWRYPTS_LIBRARY'"

View File

@ -12,10 +12,7 @@ SCWRYPTS__RUN() { # context wrapper to run scwrypts within scwrypts
local EXIT_CODE=0 local EXIT_CODE=0
((SUBSCWRYPT+=1)) ((SUBSCWRYPT+=1))
SCWRYPTS_LOG_LEVEL=$SCWRYPTS_LOG_LEVEL \ SUBSCWRYPT=$SUBSCWRYPT $SCWRYPTS_ROOT/scwrypts $@
SUBSCWRYPT=$SUBSCWRYPT \
$SCWRYPTS_ROOT__scwrypts/scwrypts $@
EXIT_CODE=$? EXIT_CODE=$?
((SUBSCWRYPT-=1)) ((SUBSCWRYPT-=1))

View File

@ -12,7 +12,7 @@ SCWRYPTS__GET_AVAILABLE_SCWRYPTS() {
local GROUP GROUP_PATH GROUP_COLOR LOOKUP_PIDS=() local GROUP GROUP_PATH GROUP_COLOR LOOKUP_PIDS=()
{ {
echo 'NAME^TYPE^GROUP' echo 'NAME^TYPE^GROUP'
for GROUP in ${SCWRYPTS_GROUPS[@]} for GROUP in ${SCWRYPTS_GROUPS}
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)
@ -94,7 +94,7 @@ SCWRYPTS__GET_RUNSTRING() {
} }
RUNSTRING="SCWRYPTS_ENV=$ENV_NAME; $RUNSTRING" RUNSTRING="SCWRYPTS_ENV=$ENV_NAME; $RUNSTRING"
RUNSTRING="source $SCWRYPTS_ROOT__scwrypts/zsh/lib/import.driver.zsh; $RUNSTRING" RUNSTRING="source $SCWRYPTS_ROOT/zsh/lib/import.driver.zsh; $RUNSTRING"
local _VIRTUALENV=$(eval echo '$SCWRYPTS_VIRTUALENV_PATH__'$SCWRYPT_GROUP'/$SCWRYPT_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"

View File

@ -74,8 +74,6 @@ _VIRTUALENV__GET_PATH() {
local ENV_PATH="$(eval echo '$SCWRYPTS_VIRTUALENV_PATH__'$GROUP 2>/dev/null)" local ENV_PATH="$(eval echo '$SCWRYPTS_VIRTUALENV_PATH__'$GROUP 2>/dev/null)"
[ ! $ENV_PATH ] && ENV_PATH="$SCWRYPTS_VIRTUALENV_PATH__scwrypts" [ ! $ENV_PATH ] && ENV_PATH="$SCWRYPTS_VIRTUALENV_PATH__scwrypts"
mkdir -p "$ENV_PATH/$TYPE" &>/dev/null
echo $ENV_PATH/$TYPE echo $ENV_PATH/$TYPE
} }
@ -97,7 +95,7 @@ CREATE_VIRTUALENV__scwrypts__py() {
} }
done done
[ ! $PYTHON ] && { [ ! $PYTHON ] && {
ERROR 'python>=3.10 not available; skipping python env' ERROR 'python>=3.9 not available; skipping python env'
return 1 return 1
} }
@ -124,7 +122,7 @@ UPDATE_VIRTUALENV__scwrypts__py() {
PIP_INSTALL_ARGS+=(--no-cache-dir) PIP_INSTALL_ARGS+=(--no-cache-dir)
PIP_INSTALL_ARGS+=(-r requirements.txt) PIP_INSTALL_ARGS+=(-r requirements.txt)
cd "$SCWRYPTS_ROOT__scwrypts/py" cd "$SCWRYPTS_ROOT/py"
pip install ${PIP_INSTALL_ARGS[@]} pip install ${PIP_INSTALL_ARGS[@]}
} }
@ -161,9 +159,7 @@ ACTIVATE_VIRTUALENV__scwrypts__zx() {
UPDATE_VIRTUALENV__scwrypts__zx() { UPDATE_VIRTUALENV__scwrypts__zx() {
local NPM_INSTALL_ARGS=() local NPM_INSTALL_ARGS=()
[ $CI ] && NPM_INSTALL_ARGS+=(--ignore-scripts) cd "$SCWRYPTS_ROOT/zx"
cd "$SCWRYPTS_ROOT__scwrypts/zx"
npm install ${NPM_INSTALL_ARGS[@]} npm install ${NPM_INSTALL_ARGS[@]}
} }

View File

@ -1,8 +1,5 @@
FZF() { FZF() {
[ $CI ] && { [ $CI ] && FAIL 1 'currently in CI, but FZF requires user input'
DEBUG "invoked FZF with $@"
FAIL 1 'currently in CI, but FZF requires user input'
}
local FZF_ARGS=() local FZF_ARGS=()

View File

@ -5,61 +5,34 @@ PRINT() {
local STDOUT=0 local STDOUT=0
local LTRIM=1 local LTRIM=1
local FORMAT=$SCWRYPTS_OUTPUT_FORMAT
local _S
while [[ $# -gt 0 ]] while [[ $# -gt 0 ]]
do do
_S=1
case $1 in case $1 in
-n | --no-trim-tabs ) LTRIM=0 ;; -n | --no-trim-tabs ) LTRIM=0 ;;
-x | --no-line-end ) LAST_LINE_END='' ;; -x | --no-line-end ) LAST_LINE_END='' ;;
-o | --use-stdout ) STDOUT=1; STDERR=0 ;; -o | --use-stdout ) STDOUT=1; STDERR=0 ;;
-f | --format ) ((_S+=1)); FORMAT=$2 ;;
* ) MESSAGE+="$(echo $1) " ;; * ) MESSAGE+="$(echo $1) " ;;
esac esac
shift $_S shift 1
done done
[ $FORMAT ] || FORMAT=pretty MESSAGE="$(echo "$MESSAGE" | sed 's/%/%%/g')"
local STYLED_MESSAGE
case $FORMAT in
pretty )
STYLED_MESSAGE="$(echo "$MESSAGE" | sed 's/%/%%/g')"
STYLED_MESSAGE="$({
printf "${COLOR}"
while IFS='' read line
do
[[ $PREFIX =~ ^[[:space:]]\+$ ]] && printf '\n'
printf "${PREFIX} : $(echo "$line" | sed 's/^ \+//; s/ \+$//')" local STYLED_MESSAGE="$({
printf "${COLOR}"
while IFS='' read line
do
[[ $PREFIX =~ ^[[:space:]]\+$ ]] && printf '\n'
PREFIX=$(echo $PREFIX | sed 's/./ /g') printf "${PREFIX} : $(echo "$line" | sed 's/^ \+//; s/ \+$//')"
done <<< $MESSAGE
})"
STYLED_MESSAGE="${COLOR}$(echo "$STYLED_MESSAGE" | sed 's/%/%%/g')${__COLOR_RESET}${LAST_LINE_END}"
;;
json )
STYLED_MESSAGE="$(
echo '{}' | jq -c ".
| .timestamp = \"$(date +%s)\"
| .runtime = \"$SCWRYPTS_RUNTIME_ID\"
| .status = \"$(echo "$PREFIX" | sed 's/ .*//')\"
| .message = $(echo $MESSAGE | sed 's/^\t\+//' | jq -Rs)
" | sed 's/\\/\\\\/g'
)\n"
;;
* )
echo "ERROR : unsupported format '$FORMAT'" >&2
return 1
;;
esac
PREFIX=$(echo $PREFIX | sed 's/./ /g')
done <<< $MESSAGE
})"
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"
return 0 return 0
} }

View File

@ -72,7 +72,7 @@ CHECK_ENVIRONMENT() {
$E "environment errors found (see above)\n$ERROR_MESSAGE" $E "environment errors found (see above)\n$ERROR_MESSAGE"
} }
[[ $MISSING_ENVIRONMENT_VARIABLES -ne 0 ]] && [[ $__SCWRYPT ]] && { [[ $MISSING_ENVIRONMENT_VARIABLES -ne 0 ]] && {
REMINDER " REMINDER "
to quickly update missing environment variables, run: to quickly update missing environment variables, run:
'scwrypts zsh/scwrypts/environment/edit' 'scwrypts zsh/scwrypts/environment/edit'