From 2f78beaf905d4b6afd1698b141c32fb21f5069f1 Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:31:36 +0800 Subject: [PATCH] Rewrote fish plugin --- shell/navi.plugin.fish | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/shell/navi.plugin.fish b/shell/navi.plugin.fish index 5ee6c89..2de4c74 100644 --- a/shell/navi.plugin.fish +++ b/shell/navi.plugin.fish @@ -1,29 +1,19 @@ function _navi_smart_replace - set -l current_process (commandline -p | string trim) + set --local query (commandline --current-process | string trim) - 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 + if test -n "$query" + set --local best_match (navi --print --query "$query" --best-match) + if test -n "$best_match" + commandline --current-process $best_match return end - - if test -z "$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 - commandline -f repaint + set --local candidate (navi --print --query "$query") + if test -n "$candidate" + commandline --current-process $candidate + end end -if test $fish_key_bindings = fish_default_key_bindings - bind \cg _navi_smart_replace -else - bind -M insert \cg _navi_smart_replace -end +bind \cg _navi_smart_replace +bind --mode insert \cg _navi_smart_replace