Add MVP for zsh widget (#50)

Related: #37
This commit is contained in:
Denis Isidoro 2019-09-23 18:14:58 -03:00 committed by GitHub
parent c4e9c7a90a
commit 95fc254736
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 3 deletions

View file

@ -8,5 +8,6 @@ export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "${SCRIPT_DIR}" cd "${SCRIPT_DIR}"
find . -iname '*.sh' | xargs -I% dot code beautify % find . -iname '*.sh' | xargs -I% dot code beautify %
find scripts/* | xargs -I% dot code beautify % find scripts/* | xargs -I% dot code beautify %
find shell/* | xargs -I% dot code beautify %
dot code beautify "${SCRIPT_DIR}/test/run" dot code beautify "${SCRIPT_DIR}/test/run"
dot code beautify "${SCRIPT_DIR}/navi" dot code beautify "${SCRIPT_DIR}/navi"

9
shell/widget.zsh Normal file
View file

@ -0,0 +1,9 @@
_call_navi() {
# zle kill-whole-line
zle -U "$(NAVI_FZF_ALL_INPUTS=true navi --print "$(echo "$CUTBUFFER" | xargs)" <> /dev/tty)"
zle accept-line
}
zle -N _call_navi
bindkey '\eg' _call_navi

View file

@ -60,10 +60,15 @@ arg::pick() {
done done
if [ -n "$fn" ]; then if [ -n "$fn" ]; then
eval "$fn" | ui::pick --prompt "$arg: " --header-lines "${headers:-0}" | str::column "${column:-}" local suggestions="$(eval "$fn" 2>/dev/null)"
if [ -n "$suggestions" ]; then
echo "$suggestions" | ui::pick --prompt "$arg: " --header-lines "${headers:-0}" | str::column "${column:-}"
fi
elif ${NAVI_FZF_ALL_INPUTS:-false}; then
echo "" | ui::pick --prompt "$arg: " --print-query --height 1
else else
printf "\033[0;36m${arg}:\033[0;0m " > /dev/tty printf "\033[0;36m${arg}:\033[0;0m " > /dev/tty
read value read -r value
ui::clear_previous_line > /dev/tty ui::clear_previous_line > /dev/tty
printf "$value" printf "$value"
fi fi

View file

@ -30,7 +30,7 @@ handler::main() {
value="$(arg::pick "$arg" "$cheat" || echo "")" value="$(arg::pick "$arg" "$cheat" || echo "")"
if [ -z "$value" ]; then if [ -z "$value" ]; then
echo "$cmd" echoerr "Unable to fetch suggestions for '$arg'!"
exit 0 exit 0
fi fi