[zsh-completion] Fix error with backslash-prefixed commands

Fix #1973
Fix #1974
Fix #1975
This commit is contained in:
Junegunn Choi 2020-04-13 00:30:43 +09:00
parent 5deaf58928
commit dea206b023
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
2 changed files with 14 additions and 1 deletions

View File

@ -117,6 +117,7 @@ __fzf_extract_command() {
local token tokens
tokens=(${(z)1})
for token in $tokens; do
token=${(Q)token}
if [[ "$token" =~ [[:alnum:]] && ! "$token" =~ "=" ]]; then
echo "$token"
return
@ -275,7 +276,7 @@ fzf-completion() {
tail=${LBUFFER:$(( ${#LBUFFER} - ${#trigger} ))}
# Kill completion (do not require trigger sequence)
if [ $cmd = kill -a ${LBUFFER[-1]} = ' ' ]; then
if [ "$cmd" = kill -a ${LBUFFER[-1]} = ' ' ]; then
matches=$(command ps -ef | sed 1d | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-50%} --min-height 15 --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS --preview 'echo {}' --preview-window down:3:wrap" __fzf_comprun "$cmd" -m | awk '{print $2}' | tr '\n' ' ')
if [ -n "$matches" ]; then
LBUFFER="$LBUFFER$matches"

View File

@ -2133,6 +2133,18 @@ class TestZsh < TestBase
tmux.send_keys "FZF_TMUX=1 #{Shell.zsh}", :Enter
tmux.prepare
end
def test_complete_quoted_command
tmux.send_keys 'export FZFFOOBAR=BAZ', :Enter
['unset', '\unset', "'unset'"].each do |command|
tmux.prepare
tmux.send_keys "#{command} FZFFOOBR**", :Tab
tmux.until { |lines| lines.match_count == 1 }
tmux.send_keys :Enter
tmux.until { |lines| lines[-1].include?("#{command} FZFFOOBAR") }
tmux.send_keys 'C-c'
end
end
end
class TestFish < TestBase