From 023e52d1fbda6a2ca53e8b06fbc1845519007c46 Mon Sep 17 00:00:00 2001 From: Lam Chau Date: Fri, 6 Jun 2025 02:09:06 -0700 Subject: [PATCH 1/5] fix: prevent prompt corruption in fish v4 fish v4 introduced new multiline prompt rendering behavior that breaks when interactive commands like `navi` are injected via keybindings. this resulted in partial prefix symbols (e.g. from a prompt's newline component) being left on screen and improperly rendering the expanded command (e.g. `gzgzip` instead of `gzip`). this forces a full redraw so it's cosmetically identical to running `navi` (as a command without insertion) --- shell/navi.plugin.fish | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/navi.plugin.fish b/shell/navi.plugin.fish index 2de4c74..419906e 100644 --- a/shell/navi.plugin.fish +++ b/shell/navi.plugin.fish @@ -5,6 +5,7 @@ function _navi_smart_replace set --local best_match (navi --print --query "$query" --best-match) if test -n "$best_match" commandline --current-process $best_match + commandline -f repaint return end end @@ -12,6 +13,7 @@ function _navi_smart_replace set --local candidate (navi --print --query "$query") if test -n "$candidate" commandline --current-process $candidate + commandline -f repaint end end From 0076018ada7b294df87df365304d1abc71c6ce4a Mon Sep 17 00:00:00 2001 From: Lam Chau Date: Fri, 6 Jun 2025 13:24:02 -0700 Subject: [PATCH 2/5] fix: add version check for fish v4+ --- shell/navi.plugin.fish | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/shell/navi.plugin.fish b/shell/navi.plugin.fish index 419906e..4b05a40 100644 --- a/shell/navi.plugin.fish +++ b/shell/navi.plugin.fish @@ -1,11 +1,24 @@ function _navi_smart_replace set --local query (commandline --current-process | string trim) + set --local version_parts "" + if test -n "$version" + set version_parts (string split '.' $version) + else + set version_parts (string split '.' (string match -r '\d+\.\d+\.\d+' (fish --version))) + end + + set --local force_repaint false + if test $version_parts[1] -ge 4 + set force_repaint true + end if test -n "$query" set --local best_match (navi --print --query "$query" --best-match) if test -n "$best_match" commandline --current-process $best_match - commandline -f repaint + if test "$force_repaint" = true + commandline -f repaint + end return end end @@ -13,7 +26,9 @@ function _navi_smart_replace set --local candidate (navi --print --query "$query") if test -n "$candidate" commandline --current-process $candidate - commandline -f repaint + if test "$force_repaint" = true + commandline -f repaint + end end end From fcbd6c3350bf6b382e39a1fd9c4dbb24a8b26f19 Mon Sep 17 00:00:00 2001 From: Lam Chau Date: Fri, 6 Jun 2025 19:49:35 -0700 Subject: [PATCH 3/5] style: use long options for self-documentation --- 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 4b05a40..9ecfccf 100644 --- a/shell/navi.plugin.fish +++ b/shell/navi.plugin.fish @@ -17,7 +17,7 @@ function _navi_smart_replace if test -n "$best_match" commandline --current-process $best_match if test "$force_repaint" = true - commandline -f repaint + commandline --function repaint end return end @@ -27,7 +27,7 @@ function _navi_smart_replace if test -n "$candidate" commandline --current-process $candidate if test "$force_repaint" = true - commandline -f repaint + commandline --function repaint end end end From a7efad2740096b75dbf81bbf12231127368ea572 Mon Sep 17 00:00:00 2001 From: Lam Chau Date: Sat, 7 Jun 2025 14:36:02 -0700 Subject: [PATCH 4/5] docs: add references to fish --- shell/navi.plugin.fish | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/shell/navi.plugin.fish b/shell/navi.plugin.fish index 9ecfccf..94c925a 100644 --- a/shell/navi.plugin.fish +++ b/shell/navi.plugin.fish @@ -8,6 +8,13 @@ function _navi_smart_replace end set --local force_repaint false + # https://github.com/fish-shell/fish-shell/blob/d663f553dffba460d6d0bcdf93df21bda9ec6f3f/doc_src/interactive.rst?plain=1#L440 + # > Bindings that change the mode are supposed to call the repaint-mode bind function + # + # Related issues + # - https://github.com/fish-shell/fish-shell/issues/5033 + # - https://github.com/fish-shell/fish-shell/issues/5860 + # - https://github.com/fish-shell/fish-shell/blob/d663f553dffba460d6d0bcdf93df21bda9ec6f3f/src/screen.rs#L531 if test $version_parts[1] -ge 4 set force_repaint true end From d62f8c7e04b04e3108e31dce2b9bd26d05c460be Mon Sep 17 00:00:00 2001 From: Alexis Opolka <53085471+alexis-opolka@users.noreply.github.com> Date: Tue, 10 Jun 2025 11:09:20 +0200 Subject: [PATCH 5/5] Update navi.plugin.fish --- shell/navi.plugin.fish | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/navi.plugin.fish b/shell/navi.plugin.fish index 94c925a..073051a 100644 --- a/shell/navi.plugin.fish +++ b/shell/navi.plugin.fish @@ -15,6 +15,8 @@ function _navi_smart_replace # - https://github.com/fish-shell/fish-shell/issues/5033 # - https://github.com/fish-shell/fish-shell/issues/5860 # - https://github.com/fish-shell/fish-shell/blob/d663f553dffba460d6d0bcdf93df21bda9ec6f3f/src/screen.rs#L531 + # + # Introduced with: https://github.com/denisidoro/navi/pull/982 if test $version_parts[1] -ge 4 set force_repaint true end