mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-04-21 08:51:14 -03:00
Commitcd3da62d24(fix(completion): unescape strings for __fish_complete_list, 2024-09-17) bravely addressed an issue that exists in a lot of completions. It did so only for __fish_complete_list. Fair enough. Unfortunately it unescaped more than just "$(commandline -t)". This causes the problem described at https://github.com/fish-shell/fish-shell/issues/11508#issuecomment-2889088934 where completion descriptions containing a backslash followed by "n" are interpreted as newlines, breaking the completion parser. Fix that. (cherry picked from commit60881f1195)
32 lines
1.0 KiB
Fish
32 lines
1.0 KiB
Fish
function __fish_complete_list --argument-names div cmd prefix iprefix
|
|
if not set -q cmd[1]
|
|
echo "Usage:
|
|
__fish_complete_list <separator> <function> <prefix> <itemprefix>
|
|
where:
|
|
separator - a symbol, separating individual entries
|
|
function - a function which prints a completion list to complete each entry
|
|
prefix - a prefix, which is printed before the list
|
|
itemprefix - a prefix, which is printed before each item" >/dev/stderr
|
|
return 1
|
|
end
|
|
set -q iprefix[1]
|
|
or set -l iprefix ""
|
|
set -q prefix[1]
|
|
or set -l prefix ""
|
|
set -l pat "$(commandline -t)"
|
|
if set -q __fish_stripprefix[1]
|
|
set pat "$(string replace -r -- "$__fish_stripprefix" "" $pat)"
|
|
end
|
|
switch $pat
|
|
case "*$div*"
|
|
for i in (string unescape -- $pat | sed "s/^\(.\+$div\)$iprefix.*\$/\1/")$iprefix(eval $cmd)
|
|
printf %s\n $i
|
|
end
|
|
case '*'
|
|
for i in $prefix$iprefix(eval $cmd)
|
|
printf %s\n $i
|
|
end
|
|
end
|
|
|
|
end
|