From 84d4cad40533224bc5163685204e3cda48aa5c3d Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Sun, 16 Jan 2022 18:22:32 +0800 Subject: [PATCH 1/8] Improve fish widget code --- shell/navi.plugin.fish | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/shell/navi.plugin.fish b/shell/navi.plugin.fish index d8fef0ac..6eb7f99f 100644 --- a/shell/navi.plugin.fish +++ b/shell/navi.plugin.fish @@ -1,43 +1,25 @@ -function __call_navi - navi --print -end - -function navi-widget -d "Show cheat sheets" - begin - set ttysettings (stty -g) - stty sane - __call_navi | perl -pe 'chomp if eof' | read -lz result - and commandline -- $result - - stty $ttysettings - end - commandline -f repaint -end - -# set -g navi_last_cmd "" - -function smart_replace +function _navi_smart_replace set -l current_process (commandline -p) - if [ $current_process = "" ] + if test $current_process = "" commandline -p (navi --print) commandline -f repaint else set -l best_match (navi --print --best-match --query $current_process) - if not [ $best_match > /dev/null ]; + if not test $best_match > /dev/null commandline -p $current_process commandline -f repaint return end - if [ $best_match = "" ] + if test $best_match = "" commandline -p (navi --print --query $current_process) commandline -f repaint - else if [ $current_process != $best_match ] + else if test $current_process != $best_match commandline -p $best_match commandline -f repaint - else if [ $current_process = $best_match ] + else commandline -p (navi --print --query $current_process) commandline -f repaint end @@ -45,6 +27,4 @@ function smart_replace end bind \cg smart_replace -if bind -M insert > /dev/null 2>&1 - bind -M insert \cg smart_replace -end +bind -M insert \cg smart_replace From 2bf4165e5615e7bc066fe76deb9c5bb57b7ec334 Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Sun, 16 Jan 2022 18:25:16 +0800 Subject: [PATCH 2/8] Update function name --- shell/navi.plugin.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/navi.plugin.fish b/shell/navi.plugin.fish index 6eb7f99f..ddcd3b1b 100644 --- a/shell/navi.plugin.fish +++ b/shell/navi.plugin.fish @@ -26,5 +26,5 @@ function _navi_smart_replace end end -bind \cg smart_replace -bind -M insert \cg smart_replace +bind \cg _navi_smart_replace +bind -M insert \cg _navi_smart_replace From 9186d7bb7cf1f604e4bb8851a4acee1a26650589 Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Sun, 16 Jan 2022 18:37:46 +0800 Subject: [PATCH 3/8] Trim current process --- shell/navi.plugin.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/navi.plugin.fish b/shell/navi.plugin.fish index ddcd3b1b..c076fc84 100644 --- a/shell/navi.plugin.fish +++ b/shell/navi.plugin.fish @@ -1,5 +1,5 @@ function _navi_smart_replace - set -l current_process (commandline -p) + set -l current_process (commandline -p | string trim) if test $current_process = "" commandline -p (navi --print) From 0160a44b3e1d779a80239d546d9be7cd3ba796be Mon Sep 17 00:00:00 2001 From: Kid Date: Sun, 16 Jan 2022 19:02:36 +0800 Subject: [PATCH 4/8] Insert when not doing smart replace --- shell/navi.plugin.fish | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/shell/navi.plugin.fish b/shell/navi.plugin.fish index c076fc84..280a7b38 100644 --- a/shell/navi.plugin.fish +++ b/shell/navi.plugin.fish @@ -1,29 +1,25 @@ function _navi_smart_replace set -l current_process (commandline -p | string trim) - if test $current_process = "" - commandline -p (navi --print) - commandline -f repaint + if test -z $current_process + commandline -i (navi --print) else set -l best_match (navi --print --best-match --query $current_process) if not test $best_match > /dev/null - commandline -p $current_process - commandline -f repaint return end if test $best_match = "" - commandline -p (navi --print --query $current_process) - commandline -f repaint + commandline -p (navi --print --query $current_process) else if test $current_process != $best_match commandline -p $best_match - commandline -f repaint else commandline -p (navi --print --query $current_process) - commandline -f repaint end end + + commandline -f repaint end bind \cg _navi_smart_replace From 53c1ddf42fed6e70a9b29201d33f843394b3c98d Mon Sep 17 00:00:00 2001 From: Kid Date: Sun, 16 Jan 2022 19:06:09 +0800 Subject: [PATCH 5/8] Only bind insert mode when not using default keybindings --- shell/navi.plugin.fish | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/shell/navi.plugin.fish b/shell/navi.plugin.fish index 280a7b38..8f3a6699 100644 --- a/shell/navi.plugin.fish +++ b/shell/navi.plugin.fish @@ -22,5 +22,8 @@ function _navi_smart_replace commandline -f repaint end -bind \cg _navi_smart_replace -bind -M insert \cg _navi_smart_replace +if test $fish_key_bindings = fish_default_key_bindings + bind \cg _navi_smart_replace +else + bind -M insert \cg _navi_smart_replace +end From ad49f431575c99471e1da536425b41148aebaf25 Mon Sep 17 00:00:00 2001 From: Kid Date: Sun, 16 Jan 2022 19:06:57 +0800 Subject: [PATCH 6/8] Run fish_indent --- shell/navi.plugin.fish | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/shell/navi.plugin.fish b/shell/navi.plugin.fish index 8f3a6699..9d69e6fb 100644 --- a/shell/navi.plugin.fish +++ b/shell/navi.plugin.fish @@ -1,29 +1,29 @@ function _navi_smart_replace - set -l current_process (commandline -p | string trim) + set -l current_process (commandline -p | string trim) - if test -z $current_process - commandline -i (navi --print) - else - set -l best_match (navi --print --best-match --query $current_process) + if test -z $current_process + commandline -i (navi --print) + else + set -l best_match (navi --print --best-match --query $current_process) - if not test $best_match > /dev/null - return - end + if not test $best_match >/dev/null + return + end - if test $best_match = "" - commandline -p (navi --print --query $current_process) - else if test $current_process != $best_match - commandline -p $best_match - else - commandline -p (navi --print --query $current_process) + if test $best_match = "" + commandline -p (navi --print --query $current_process) + else if test $current_process != $best_match + commandline -p $best_match + else + commandline -p (navi --print --query $current_process) + end end - end - commandline -f repaint + commandline -f repaint end if test $fish_key_bindings = fish_default_key_bindings - bind \cg _navi_smart_replace + bind \cg _navi_smart_replace else - bind -M insert \cg _navi_smart_replace + bind -M insert \cg _navi_smart_replace end From 9f35e3ef6963331b740bb0bf5fd7cd1cabf005de Mon Sep 17 00:00:00 2001 From: Kid Date: Sun, 16 Jan 2022 19:17:28 +0800 Subject: [PATCH 7/8] Quotes --- shell/navi.plugin.fish | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/navi.plugin.fish b/shell/navi.plugin.fish index 9d69e6fb..4c4a4c55 100644 --- a/shell/navi.plugin.fish +++ b/shell/navi.plugin.fish @@ -1,18 +1,18 @@ function _navi_smart_replace set -l current_process (commandline -p | string trim) - if test -z $current_process + if test -z "$current_process" commandline -i (navi --print) else - set -l best_match (navi --print --best-match --query $current_process) + set -l best_match (navi --print --best-match --query "$current_process") - if not test $best_match >/dev/null + if not test "$best_match" >/dev/null return end - if test $best_match = "" + if test -z "$best_match" commandline -p (navi --print --query $current_process) - else if test $current_process != $best_match + else if test "$current_process" != "$best_match" commandline -p $best_match else commandline -p (navi --print --query $current_process) From 462a55358c51b203b08b187abfbc228e3138d086 Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Mon, 17 Jan 2022 07:54:29 +0800 Subject: [PATCH 8/8] Quote more --- shell/navi.plugin.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/navi.plugin.fish b/shell/navi.plugin.fish index 4c4a4c55..5ee6c89c 100644 --- a/shell/navi.plugin.fish +++ b/shell/navi.plugin.fish @@ -11,11 +11,11 @@ function _navi_smart_replace end if test -z "$best_match" - commandline -p (navi --print --query $current_process) + commandline -p (navi --print --query "$current_process") else if test "$current_process" != "$best_match" commandline -p $best_match else - commandline -p (navi --print --query $current_process) + commandline -p (navi --print --query "$current_process") end end