From dea206b023a695b75540f642a0b19a3ba1e38eec Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 13 Apr 2020 00:30:43 +0900 Subject: [PATCH] [zsh-completion] Fix error with backslash-prefixed commands Fix #1973 Fix #1974 Fix #1975 --- shell/completion.zsh | 3 ++- test/test_go.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/shell/completion.zsh b/shell/completion.zsh index 7e9f83a..3381f46 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -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" diff --git a/test/test_go.rb b/test/test_go.rb index 6f31dcf..586ddf9 100755 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -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