cleaned up environment requirements for zsh plugin

This commit is contained in:
Wryn (yage) Wagner 2024-05-07 23:16:29 -06:00
parent 71ba353fab
commit 9288e6642b

View File

@ -2,47 +2,44 @@
: \
&& command -v scwrypts &>/dev/null \
&& source "$(scwrypts --root)/zsh/lib/import.driver.zsh" \
&& unset __SCWRYPT \
&& eval "$(scwrypts --config)" \
|| {
echo 'scwrypts must be in PATH and properly configured; skipping zsh plugin setup' >&2
return 0
}
__SCWRYPTS_PARSE() {
SCWRYPT_SELECTION=$(scwrypts --list | fzf --prompt 'select a script : ' --header-lines 1)
LBUFFER= RBUFFER=
[ $SCWRYPT_SELECTION ] || return 1
NAME=$(echo "$SCWRYPT_SELECTION" | awk '{print $1;}')
TYPE=$(echo "$SCWRYPT_SELECTION" | awk '{print $2;}')
GROUP=$(echo "$SCWRYPT_SELECTION" | awk '{print $3;}')
[ $NAME ] && [ $TYPE ] && [ $GROUP ]
}
#####################################################################
SCWRYPTS__ZSH_PLUGIN() {
local SCWRYPT_SELECTION=$(scwrypts --list | FZF 'select a script' --header-lines 1)
local NAME
local TYPE
local GROUP
LBUFFER= RBUFFER=
[ ! $SCWRYPT_SELECTION ] && { zle accept-line; return 0; }
local SCWRYPT_SELECTION NAME TYPE GROUP
__SCWRYPTS_PARSE || { zle accept-line; return 0; }
SCWRYPTS__SEPARATE_SCWRYPT_SELECTION $SCWRYPT_SELECTION
which scwrypts >/dev/null 2>&1\
&& RBUFFER="scwrypts" || RBUFFER="$SCWRYPTS_ROOT/scwrypts"
RBUFFER+=" --name $NAME --group $GROUP --type $TYPE"
RBUFFER="scwrypts --name $NAME --type $TYPE --group $GROUP"
zle accept-line
}
zle -N scwrypts SCWRYPTS__ZSH_PLUGIN
bindkey $SCWRYPTS_SHORTCUT scwrypts
unset SCWRYPTS_SHORTCUT
#####################################################################
SCWRYPTS__ZSH_BUILDER_PLUGIN() {
local SCWRYPT_SELECTION=$(scwrypts --list | FZF 'select a script' --header-lines 1)
local SCWRYPT_SELECTION NAME TYPE GROUP
__SCWRYPTS_PARSE || { echo >&2; zle accept-line; return 0; }
echo $SCWRYPT_SELECTION >&2
local NAME
local TYPE
local GROUP
LBUFFER= RBUFFER=
[ ! $SCWRYPT_SELECTION ] && { zle accept-line; return 0; }
SCWRYPTS__SEPARATE_SCWRYPT_SELECTION $SCWRYPT_SELECTION
scwrypts -n --name $NAME --group $GROUP --type $TYPE -- --help >&2 || {
zle accept-line
@ -51,22 +48,20 @@ SCWRYPTS__ZSH_BUILDER_PLUGIN() {
echo
zle reset-prompt
which scwrypts >/dev/null 2>&1\
&& LBUFFER="scwrypts" || LBUFFER="$SCWRYPTS_ROOT/scwrypts"
LBUFFER+=" --name $NAME --group $GROUP --type $TYPE -- "
LBUFFER="scwrypts --name $NAME --type $TYPE --group $GROUP -- "
}
zle -N scwrypts-builder SCWRYPTS__ZSH_BUILDER_PLUGIN
bindkey $SCWRYPTS_BUILDER_SHORTCUT scwrypts-builder
unset SCWRYPTS_BUILDER_SHORTCUT
#####################################################################
SCWRYPTS__ZSH_PLUGIN_ENV() {
local RESET='reset'
local SELECTED=$(\
{ [ $SCWRYPTS_ENV ] && echo $RESET; SCWRYPTS__GET_ENV_NAMES; } \
| FZF 'select an environment' \
{ [ $SCWRYPTS_ENV ] && echo $RESET; scwrypts --list-envs; } \
| fzf --prompt 'select an environment : ' \
)
zle clear-command-line
@ -80,3 +75,6 @@ SCWRYPTS__ZSH_PLUGIN_ENV() {
zle -N scwrypts-setenv SCWRYPTS__ZSH_PLUGIN_ENV
bindkey $SCWRYPTS_ENV_SHORTCUT scwrypts-setenv
unset SCWRYPTS_ENV_SHORTCUT
#####################################################################