mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-19 00:53:42 -05:00
Fix bad escaping in fzf-complete
@@ -49,22 +49,24 @@ The following can replace fish completion menu with fzf. Because of a [fish bug]
|
|||||||
function fzf-complete -d 'fzf completion and print selection back to commandline'
|
function fzf-complete -d 'fzf completion and print selection back to commandline'
|
||||||
set -l complist (complete -C(commandline -c))
|
set -l complist (complete -C(commandline -c))
|
||||||
set -l result
|
set -l result
|
||||||
string join -- \n $complist | sort | eval (__fzfcmd) -m --tiebreak=index --select-1 --exit-0 --header '(commandline)' | cut -f1 | while read -l r; set result $result $r; end
|
string join -- \n $complist | sort | fzf -m --select-1 --exit-0 --header '(commandline)' | cut -f1 | while read -l r; set result $result $r; end
|
||||||
|
|
||||||
|
set prefix (string sub -s 1 -l 1 -- (commandline -t))
|
||||||
for i in (seq (count $result))
|
for i in (seq (count $result))
|
||||||
set -l r $result[$i]
|
set -l r $result[$i]
|
||||||
## We need to escape the result.
|
switch $prefix
|
||||||
switch (string sub -s 1 -l 1 -- (commandline -t))
|
|
||||||
case "'"
|
case "'"
|
||||||
commandline -t -- (string escape -- (eval "printf '%s' '$r'"))
|
commandline -t -- (string escape -- $r)
|
||||||
case '"'
|
case '"'
|
||||||
set -l quoted (string escape -- (eval "printf '%s' '$r'"))
|
if string match '*"*' -- $r >/dev/null
|
||||||
set -l len (string length $quoted)
|
commandline -t -- (string escape -- $r)
|
||||||
commandline -t -- '"'(string sub -s 2 -l (math $len - 2) (string escape -- (eval "printf '%s' '$r'")))'"'
|
else
|
||||||
|
commandline -t -- '"'$r'"'
|
||||||
|
end
|
||||||
case '~'
|
case '~'
|
||||||
commandline -t -- (string sub -s 2 (string escape -n -- (eval "printf '%s' '$r'")))
|
commandline -t -- (string sub -s 2 (string escape -n -- $r))
|
||||||
case '*'
|
case '*'
|
||||||
commandline -t -- (string escape -n -- (eval "printf '%s' '$r'"))
|
commandline -t -- (string escape -n -- $r)
|
||||||
end
|
end
|
||||||
[ $i -lt (count $result) ]; and commandline -i ' '
|
[ $i -lt (count $result) ]; and commandline -i ' '
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user