From 6b6c9938aa0d4163ddf24f2291424b4ee1202b72 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Thu, 25 May 2017 19:29:42 +0200 Subject: [PATCH] Fix bad escaping in fzf-complete --- Examples-(fish).md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Examples-(fish).md b/Examples-(fish).md index 20b5675..b2f5a73 100644 --- a/Examples-(fish).md +++ b/Examples-(fish).md @@ -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' set -l complist (complete -C(commandline -c)) 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)) set -l r $result[$i] - ## We need to escape the result. - switch (string sub -s 1 -l 1 -- (commandline -t)) + switch $prefix case "'" - commandline -t -- (string escape -- (eval "printf '%s' '$r'")) + commandline -t -- (string escape -- $r) case '"' - set -l quoted (string escape -- (eval "printf '%s' '$r'")) - set -l len (string length $quoted) - commandline -t -- '"'(string sub -s 2 -l (math $len - 2) (string escape -- (eval "printf '%s' '$r'")))'"' + if string match '*"*' -- $r >/dev/null + commandline -t -- (string escape -- $r) + else + commandline -t -- '"'$r'"' + end 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 '*' - commandline -t -- (string escape -n -- (eval "printf '%s' '$r'")) + commandline -t -- (string escape -n -- $r) end [ $i -lt (count $result) ]; and commandline -i ' ' end