Fix __fish_list_current_token and friends for multiline commandlines

Some of these handled multiline prompts but not multiline command lines. We
first need to move the cursor to the end of the commandline, then we can
print a message.  Finally, we need to move the cursor back to where it was.
This commit is contained in:
Johannes Altmanninger 2024-04-11 12:34:58 +02:00
parent 8386088b3d
commit 9158395d10
6 changed files with 29 additions and 34 deletions

View File

@ -114,6 +114,7 @@ New or improved bindings
- The editor's cursor position is copied back to fish. This is currently supported for Vim and Kakoune.
- Cursor position synchronization is only supported for a set of known editors. This has been extended by also resolving aliases. For example use ``complete --wraps my-vim vim`` to synchronize cursors when `EDITOR=my-vim`.
- ``backward-kill-path-component`` and friends now treat ``#`` as part of a path component (:issue:`10271`).
- Bindings like :kbd:`alt-l` that print output in between prompts now work correctly with multiline commandlines.
- The ``E`` binding in vi mode now correctly handles the last character of the word, by jumping to the next word (:issue:`9700`).
- If the terminal supports shifted key codes from the [kitty keyboard protocol](https://sw.kovidgoyal.net/kitty/keyboard-protocol/), ``shift-enter`` now inserts a newline instead of executing the command line.
- Vi mode has seen some improvements but continues to suffer from the lack of people working on it.

View File

@ -5,10 +5,9 @@ function __fish_anyeditor --description "Print a editor to use, or an error mess
else if set -q EDITOR
echo $EDITOR | read -at editor
else
echo >&2
echo >&2 (_ 'External editor requested but $VISUAL or $EDITOR not set.')
echo >&2 (_ 'Please set VISUAL or EDITOR to your preferred editor.')
commandline -f repaint
__fish_echo string join \n -- \
(_ 'External editor requested but $VISUAL or $EDITOR not set.') \
(_ 'Please set VISUAL or EDITOR to your preferred editor.')
return 1
end
string join \n $editor

View File

@ -0,0 +1,8 @@
function __fish_echo --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
string >&2 repeat -N \n --count=(math (count (fish_prompt)) - 1)
string >&2 repeat -N \n --count=(math $line - 1)
commandline -f repaint
end

View File

@ -3,19 +3,16 @@
function __fish_list_current_token -d "List contents of token under the cursor if it is a directory, otherwise list the contents of the current directory"
set -l val (commandline -t | string replace -r '^~' "$HOME")
printf "\n"
set -l cmd
if test -d $val
ls $val
set cmd ls $val
else
set -l dir (dirname -- $val)
if test $dir != . -a -d $dir
ls $dir
set cmd ls $dir
else
ls
set cmd ls
end
end
string repeat -N \n --count=(math (count (fish_prompt)) - 1)
commandline -f repaint
__fish_echo $cmd
end

View File

@ -6,7 +6,6 @@ function __fish_whatis_current_token -d "Show man page entries or function descr
test -n "$token"
or return
printf "\n"
set -l desc "$token: nothing appropriate."
set -l tokentype (type --type $token 2>/dev/null)
@ -26,9 +25,5 @@ function __fish_whatis_current_token -d "Show man page entries or function descr
and set desc $tmpdesc
end
printf "%s\n" $desc
string repeat -N \n --count=(math (count (fish_prompt)) - 1)
commandline -f repaint
__fish_echo string join \n -- $desc
end

View File

@ -27,30 +27,25 @@ function fish_job_summary -a job_id is_foreground cmd_line signal_or_end_name si
set -l max_cmd_len 32
set cmd_line (string shorten -m$max_cmd_len -- $cmd_line)
if test $is_foreground -eq 0; and test $signal_or_end_name != STOPPED
# Add a newline *before* our message so we get the message after the commandline.
echo >&2
end
set -l message
switch $signal_or_end_name
case STOPPED
printf ( _ "fish: Job %s, '%s' has stopped\n" ) $job_id $cmd_line
set message (printf ( _ "fish: Job %s, '%s' has stopped\n" ) $job_id $cmd_line)
case ENDED
printf ( _ "fish: Job %s, '%s' has ended\n" ) $job_id $cmd_line
set message (printf ( _ "fish: Job %s, '%s' has ended\n" ) $job_id $cmd_line)
case 'SIG*'
if test -n "$proc_pid"
printf ( _ "fish: Process %s, '%s' from job %s, '%s' terminated by signal %s (%s)\n" ) \
$proc_pid $proc_name $job_id $cmd_line $signal_or_end_name $signal_desc
set message (printf ( _ "fish: Process %s, '%s' from job %s, '%s' terminated by signal %s (%s)\n" ) \
$proc_pid $proc_name $job_id $cmd_line $signal_or_end_name $signal_desc)
else
printf ( _ "fish: Job %s, '%s' terminated by signal %s (%s)\n" ) \
$job_id $cmd_line $signal_or_end_name $signal_desc
set message (printf ( _ "fish: Job %s, '%s' terminated by signal %s (%s)\n" ) \
$job_id $cmd_line $signal_or_end_name $signal_desc)
end
end
end >&2
if test $is_foreground -eq 0; and test $signal_or_end_name != STOPPED
# We want one newline per line in the prompt after the first.
# To ensure that, don't let `string repeat` add a newline. See #9044.
string repeat -N \n --count=(math (count (fish_prompt)) - 1) >&2
commandline -f repaint
__fish_echo string join \n -- $message
else
string join >&2 \n -- $message
end
end