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] 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 d8fef0a..6eb7f99 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