Files
scwrypts/scwrypts.plugin.zsh
T

98 lines
2.6 KiB
Bash
Raw Permalink Normal View History

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