From 1fdf37cc4a2321bb5b49b3fb1ebc5cb2f74c2791 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 17 Sep 2025 11:33:43 +0200 Subject: [PATCH] __fish_echo: fully overwrite lines With upcoming multi-line autosuggestions, when I run $ function foo true end and type "function", then I'll get a suggestion for the above command. Now if press "alt-w", it will echo "function - create a function" and rewdraw the prompt below. But the previous autosuggestion is not cleared, so it will look weird like: johannes@abc ~/g/fish-shell> function foo function - create a function true Let's erase these lines before writing them. There's an issue remaining: the first line of the autosuggestion (i.e. "foo") is not erased. Fortunately this is less annoying, but it shows that __fish_echo needs more support from core. --- share/functions/__fish_echo.fish | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/share/functions/__fish_echo.fish b/share/functions/__fish_echo.fish index 94768fbdc..9f0948799 100644 --- a/share/functions/__fish_echo.fish +++ b/share/functions/__fish_echo.fish @@ -1,7 +1,15 @@ -function __fish_echo --description 'run the given command after the current commandline and redraw the prompt' +set -l erase_line "$( + if status test-feature ignore-terminfo + echo \e\[K + else if type -q tput + tput el + end +)" + +function __fish_echo --inherit-variable erase_line --description 'run the given command after the current commandline and redraw the prompt' set -l line (commandline --line) string >&2 repeat -N \n --count=(math (commandline | count) - $line + 1) - $argv >&2 + printf %s\n $erase_line($argv) >&2 string >&2 repeat -N \n --count=(math (count (fish_prompt)) - 1) string >&2 repeat -N \n --count=(math $line - 1) commandline -f repaint