scwrypts/scwrypts.plugin.zsh
yage 6fe5b8e26a v4.2.0
=====================================================================

DEPRECATION REMINDER!

The following functions and APIS are no longer available:

- FZF_HEAD : use FZF as a drop-in replacement
- FZF_TAIL : use FZF as a drop-in replacement

- SCWRYPTS__GET_RUNSTRING__zsh_v3 : upgrade to zsh/scwrypts v4
                                    runstrings

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

- removed legacy INFO references in plugins/kubectl

- the zsh-builder plugin (CTRL+Y) now show clean helpdocs (no more
  visual terminal artifacts)

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

- differentiate manual / managed versions of scwrypts in versioning;
  this will prevent 'scwrypts --update' from operating against managed
  installations

- created SCWRYPTS__GET_RUNSTRING__zsh__generic to provide an easy way
  to write custom runstrings; this will do all the nice things default
  zsh/scwrypts v4 do (multiflag separation, help flag injection, USAGE
  definitions, and required MAIN() {} wrapper).
2024-04-13 17:34:22 -06:00

81 lines
2.1 KiB
Bash

#####################################################################
command -v scwrypts &>/dev/null || {
echo 'scwrypts is required in your PATH in order to use the zsh plugins; skipping' >&2
return 0
}
NO_EXPORT_CONFIG=1 source "${0:a:h}/zsh/lib/import.driver.zsh" || return 42
#####################################################################
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; }
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"
zle accept-line
}
zle -N scwrypts SCWRYPTS__ZSH_PLUGIN
bindkey $SCWRYPTS_SHORTCUT scwrypts
#####################################################################
SCWRYPTS__ZSH_BUILDER_PLUGIN() {
local SCWRYPT_SELECTION=$(scwrypts --list | FZF 'select a script' --header-lines 1)
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
return 0
}
echo
zle reset-prompt
which scwrypts >/dev/null 2>&1\
&& 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__ZSH_PLUGIN_ENV() {
local RESET='reset'
local SELECTED=$(\
{ [ $SCWRYPTS_ENV ] && echo $RESET; SCWRYPTS__GET_ENV_NAMES; } \
| FZF '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