From 95fc254736fe3e4e7def0a29387a7e88a37ceb9c Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Mon, 23 Sep 2019 18:14:58 -0300 Subject: [PATCH] Add MVP for zsh widget (#50) Related: #37 --- scripts/lint | 1 + shell/widget.zsh | 9 +++++++++ src/arg.sh | 9 +++++++-- src/main.sh | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 shell/widget.zsh diff --git a/scripts/lint b/scripts/lint index eb029f0..9ff6bfc 100755 --- a/scripts/lint +++ b/scripts/lint @@ -8,5 +8,6 @@ export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" cd "${SCRIPT_DIR}" find . -iname '*.sh' | 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}/navi" diff --git a/shell/widget.zsh b/shell/widget.zsh new file mode 100644 index 0000000..d696bd0 --- /dev/null +++ b/shell/widget.zsh @@ -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 \ No newline at end of file diff --git a/src/arg.sh b/src/arg.sh index 257979f..d0eb04f 100644 --- a/src/arg.sh +++ b/src/arg.sh @@ -60,10 +60,15 @@ arg::pick() { done 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 printf "\033[0;36m${arg}:\033[0;0m " > /dev/tty - read value + read -r value ui::clear_previous_line > /dev/tty printf "$value" fi diff --git a/src/main.sh b/src/main.sh index a228811..99d2693 100644 --- a/src/main.sh +++ b/src/main.sh @@ -30,7 +30,7 @@ handler::main() { value="$(arg::pick "$arg" "$cheat" || echo "")" if [ -z "$value" ]; then - echo "$cmd" + echoerr "Unable to fetch suggestions for '$arg'!" exit 0 fi