2024-05-08 05:11:21 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
2024-04-13 23:10:16 +00:00
|
|
|
#####################################################################
|
|
|
|
|
2024-04-15 14:45:55 +00:00
|
|
|
: \
|
|
|
|
&& command -v scwrypts &>/dev/null \
|
2024-05-08 05:11:21 +00:00
|
|
|
&& eval "$(scwrypts --config)" \
|
2024-04-15 14:45:55 +00:00
|
|
|
|| {
|
|
|
|
echo 'scwrypts must be in PATH and properly configured; skipping zsh plugin setup' >&2
|
|
|
|
return 0
|
|
|
|
}
|
2023-02-22 01:44:27 +00:00
|
|
|
|
2024-05-08 05:11:21 +00:00
|
|
|
__SCWRYPTS_PARSE() {
|
|
|
|
SCWRYPT_SELECTION=$(scwrypts --list | fzf --prompt 'select a script : ' --header-lines 1)
|
2023-12-12 00:07:09 +00:00
|
|
|
LBUFFER= RBUFFER=
|
2024-05-08 05:11:21 +00:00
|
|
|
[ $SCWRYPT_SELECTION ] || return 1
|
2023-02-22 01:44:27 +00:00
|
|
|
|
2024-05-08 05:11:21 +00:00
|
|
|
NAME=$(echo "$SCWRYPT_SELECTION" | awk '{print $1;}')
|
|
|
|
TYPE=$(echo "$SCWRYPT_SELECTION" | awk '{print $2;}')
|
|
|
|
GROUP=$(echo "$SCWRYPT_SELECTION" | awk '{print $3;}')
|
2022-04-28 22:09:23 +00:00
|
|
|
|
2024-05-08 05:11:21 +00:00
|
|
|
[ $NAME ] && [ $TYPE ] && [ $GROUP ]
|
2022-04-28 22:09:23 +00:00
|
|
|
}
|
2022-05-24 16:26:05 +00:00
|
|
|
|
2023-12-12 00:07:09 +00:00
|
|
|
#####################################################################
|
2024-04-13 23:10:16 +00:00
|
|
|
|
2024-05-08 05:11:21 +00:00
|
|
|
[ $SCWRYPTS_SHORTCUT ] && {
|
|
|
|
SCWRYPTS__ZSH_PLUGIN() {
|
|
|
|
local SCWRYPT_SELECTION NAME TYPE GROUP
|
|
|
|
__SCWRYPTS_PARSE || { zle accept-line; return 0; }
|
2023-12-12 00:07:09 +00:00
|
|
|
|
2024-05-08 05:11:21 +00:00
|
|
|
RBUFFER="scwrypts --name $NAME --type $TYPE --group $GROUP"
|
2023-12-12 00:07:09 +00:00
|
|
|
zle accept-line
|
|
|
|
}
|
|
|
|
|
2024-05-08 05:11:21 +00:00
|
|
|
zle -N scwrypts SCWRYPTS__ZSH_PLUGIN
|
|
|
|
bindkey $SCWRYPTS_SHORTCUT scwrypts
|
|
|
|
unset SCWRYPTS_SHORTCUT
|
2023-12-12 00:07:09 +00:00
|
|
|
}
|
|
|
|
|
2024-05-08 05:11:21 +00:00
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
[ $SCWRYPTS_BUILDER_SHORTCUT ] && {
|
|
|
|
SCWRYPTS__ZSH_BUILDER_PLUGIN() {
|
|
|
|
local SCWRYPT_SELECTION NAME TYPE GROUP
|
|
|
|
__SCWRYPTS_PARSE || { echo >&2; zle accept-line; return 0; }
|
|
|
|
echo $SCWRYPT_SELECTION >&2
|
|
|
|
|
|
|
|
scwrypts -n --name $NAME --group $GROUP --type $TYPE -- --help >&2 || {
|
|
|
|
zle accept-line
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
echo
|
|
|
|
|
|
|
|
zle reset-prompt
|
|
|
|
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
|
|
|
|
}
|
2023-12-12 00:07:09 +00:00
|
|
|
|
2022-04-28 22:09:23 +00:00
|
|
|
#####################################################################
|
2024-04-13 23:10:16 +00:00
|
|
|
|
2024-05-08 05:11:21 +00:00
|
|
|
[ $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
|
2022-04-28 22:09:23 +00:00
|
|
|
}
|
2024-05-08 05:11:21 +00:00
|
|
|
|
|
|
|
zle -N scwrypts-setenv SCWRYPTS__ZSH_PLUGIN_ENV
|
|
|
|
bindkey $SCWRYPTS_ENV_SHORTCUT scwrypts-setenv
|
|
|
|
unset SCWRYPTS_ENV_SHORTCUT
|
2022-04-28 22:09:23 +00:00
|
|
|
}
|
2022-05-24 16:26:05 +00:00
|
|
|
|
2024-05-08 05:11:21 +00:00
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
__SCWRYPTS_PLUGIN_LOADED=true
|