fish: Fix fzf token completion at cursor
parent
f740503fcd
commit
76d532b55c
|
@ -15,7 +15,7 @@ end
|
||||||
bind \e\cm __fzf-select
|
bind \e\cm __fzf-select
|
||||||
|
|
||||||
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)
|
set -l complist (complete -C(commandline -c))
|
||||||
set -l result
|
set -l result
|
||||||
switch (count $complist)
|
switch (count $complist)
|
||||||
case 0
|
case 0
|
||||||
|
@ -31,27 +31,21 @@ function __fzf-complete -d 'fzf completion and print selection back to commandli
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
## Remove last token from commandline.
|
|
||||||
set -l token (commandline -t)
|
|
||||||
set -l cmd (commandline)
|
|
||||||
set -l len (math (string length -- $cmd) - (string length -- $token))
|
|
||||||
commandline -- (string sub -l $len -- (commandline))
|
|
||||||
## Insert results.
|
|
||||||
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. We unescape 'r' first in case 'r' to
|
## We need to escape the result. We unescape 'r' first in case 'r' to
|
||||||
## prevent double escaping.
|
## prevent double escaping.
|
||||||
switch (string sub -s 1 -l 1 -- $token)
|
switch (string sub -s 1 -l 1 -- (commandline -t))
|
||||||
case "'"
|
case "'"
|
||||||
commandline -i -- (string escape -- (eval "printf '%s' '$r'"))
|
commandline -t -- (string escape -- (eval "printf '%s' '$r'"))
|
||||||
case '"'
|
case '"'
|
||||||
set -l quoted (string escape -- (eval "printf '%s' '$r'"))
|
set -l quoted (string escape -- (eval "printf '%s' '$r'"))
|
||||||
set -l len (string length $quoted)
|
set -l len (string length $quoted)
|
||||||
commandline -i -- '"'(string sub -s 2 -l (math $len - 2) (string escape -- (eval "printf '%s' '$r'")))'"'
|
commandline -t -- '"'(string sub -s 2 -l (math $len - 2) (string escape -- (eval "printf '%s' '$r'")))'"'
|
||||||
case '~'
|
case '~'
|
||||||
commandline -i -- (string sub -s 2 (string escape -n -- (eval "printf '%s' '$r'")))
|
commandline -t -- (string sub -s 2 (string escape -n -- (eval "printf '%s' '$r'")))
|
||||||
case '*'
|
case '*'
|
||||||
commandline -i -- (string escape -n -- (eval "printf '%s' '$r'"))
|
commandline -t -- (string escape -n -- (eval "printf '%s' '$r'"))
|
||||||
end
|
end
|
||||||
[ $i -lt (count $result) ]; and commandline -i ' '
|
[ $i -lt (count $result) ]; and commandline -i ' '
|
||||||
end
|
end
|
||||||
|
@ -91,13 +85,11 @@ function fzf-file-widget
|
||||||
if [ -n "$result" ]
|
if [ -n "$result" ]
|
||||||
if [ "$cwd" != . ]
|
if [ "$cwd" != . ]
|
||||||
## Remove last token from commandline.
|
## Remove last token from commandline.
|
||||||
set -l cmd (commandline)
|
commandline -t ""
|
||||||
set -l len (math (string length $cmd) - (string length $cwd_esc))
|
|
||||||
commandline -- (string sub -l $len (commandline))
|
|
||||||
end
|
end
|
||||||
for i in $result
|
for i in $result
|
||||||
commandline -i -- (string escape (eval "printf '%s' '$i'"))
|
commandline -it -- (string escape (eval "printf '%s' '$i'"))
|
||||||
commandline -i -- ' '
|
commandline -it -- ' '
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
|
|
Loading…
Reference in New Issue