introduce --verbosity flag rather than mixed logging settings; correct color misnaming to ANSI convention; added sanity-check; simplified hello-world; created FZF_USER_INPUT to replace the confusing FZF_HEAD and FZF_TAIL
This commit is contained in:
57
zsh/lib/utils/io.fzf.zsh
Normal file
57
zsh/lib/utils/io.fzf.zsh
Normal file
@ -0,0 +1,57 @@
|
||||
FZF() {
|
||||
[ $CI ] && FAIL 1 'currently in CI, but FZF requires user input'
|
||||
|
||||
local FZF_ARGS=()
|
||||
|
||||
FZF_ARGS+=(-i)
|
||||
FZF_ARGS+=(--ansi)
|
||||
FZF_ARGS+=(--bind=ctrl-c:cancel)
|
||||
FZF_ARGS+=(--height=50%)
|
||||
FZF_ARGS+=(--layout=reverse)
|
||||
|
||||
local SELECTION=$(fzf ${FZF_ARGS[@]} --prompt "$1 : " ${@:2})
|
||||
PROMPT "$1"
|
||||
|
||||
[ $BE_QUIET ] || {
|
||||
[[ $SCWRYPTS_LOG_LEVEL -ge 1 ]] && echo $SELECTION >&2
|
||||
}
|
||||
echo $SELECTION
|
||||
[ $SELECTION ]
|
||||
}
|
||||
|
||||
FZF_USER_INPUT() { # allow user to type custom answers; reconfirm if ambiguous with select
|
||||
local FZF_OUTPUT=$(BE_QUIET=1 FZF $@ --print-query | sed '/^$/d' | sort -u)
|
||||
[[ $SCWRYPTS_LOG_LEVEL -ge 1 ]] && echo $FZF_OUTPUT | head -n1 >&2
|
||||
[ ! $FZF_OUTPUT ] && return 1
|
||||
|
||||
[[ $(echo "$FZF_OUTPUT" | wc -l) -eq 1 ]] \
|
||||
&& { echo "$FZF_OUTPUT"; return 0; }
|
||||
|
||||
local FZF_OUTPUT=$(
|
||||
echo "$FZF_OUTPUT" \
|
||||
| sed "1s/\$/^$(printf "$__LIGHT_GRAY\\033[3m")<- what you typed$(printf $__COLOR_RESET)/" \
|
||||
| sed "2s/\$/^$(printf "$__LIGHT_GRAY\\033[3m")<- what you selected$(printf $__COLOR_RESET)/" \
|
||||
| column -ts '^' \
|
||||
| BE_QUIET=1 FZF "$@ (clarify)" \
|
||||
)
|
||||
|
||||
[[ $SCWRYPTS_LOG_LEVEL -ge 1 ]] && echo $FZF_OUTPUT >&2
|
||||
FZF_OUTPUT=$(echo $FZF_OUTPUT | sed 's/\s\+<- what you .*$//')
|
||||
echo $FZF_OUTPUT
|
||||
[ $FZF_OUTPUT ]
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
### vvv DEPRECATED vvv ##############################################
|
||||
#####################################################################
|
||||
|
||||
FZF_HEAD() { # prefer user input over selected
|
||||
WARNING 'FZF_HEAD is deprecated; please switch to FZF_USER_INPUT (drop-in fix!)'
|
||||
FZF $@ --print-query | sed '/^$/d' | head -n1;
|
||||
}
|
||||
FZF_TAIL() { # prefer selected over user input
|
||||
WARNING 'FZF_TAIL is deprecated; please switch to FZF_USER_INPUT (drop-in fix!)'
|
||||
FZF $@ --print-query | sed '/^$/d' | tail -n1;
|
||||
}
|
||||
|
||||
#####################################################################
|
Reference in New Issue
Block a user