From a568120e42a86bc37b87ae6facab91f7b35f988e Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 16 Feb 2016 12:32:05 +0900 Subject: [PATCH] Fix #494 - _fzf_complete hangs on zsh when not using tmux pane --- shell/completion.zsh | 13 ++++++++++-- test/test_go.rb | 49 ++++++++++++++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/shell/completion.zsh b/shell/completion.zsh index a1e1e079..8288cb27 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -79,8 +79,15 @@ _fzf_dir_completion() { "" "/" "" } +_fzf_feed_fifo() ( + rm -f "$fifo" + mkfifo "$fifo" + cat <&0 > "$fifo" & +) + _fzf_complete() { - local fzf_opts lbuf fzf matches post + local fifo fzf_opts lbuf fzf matches post + fifo="${TMPDIR:-/tmp}/fzf-complete-fifo-$$" fzf_opts=$1 lbuf=$2 post="${funcstack[2]}_post" @@ -88,11 +95,13 @@ _fzf_complete() { [ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf" - matches=$(cat | ${=fzf} ${=FZF_COMPLETION_OPTS} ${=fzf_opts} -q "${(Q)prefix}" | $post | tr '\n' ' ') + _fzf_feed_fifo "$fifo" + matches=$(cat "$fifo" | ${=fzf} ${=FZF_COMPLETION_OPTS} ${=fzf_opts} -q "${(Q)prefix}" | $post | tr '\n' ' ') if [ -n "$matches" ]; then LBUFFER="$lbuf$matches" fi zle redisplay + rm -f "$fifo" } _fzf_complete_telnet() { diff --git a/test/test_go.rb b/test/test_go.rb index 5ea255aa..7a2d0039 100644 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -1140,7 +1140,7 @@ class TestGoFZF < TestBase private def writelines path, lines File.unlink path while File.exists? path - File.open(path, 'w') { |f| f << lines.join($/) } + File.open(path, 'w') { |f| f << lines.join($/) + $/ } end end @@ -1355,23 +1355,42 @@ module CompletionTest tmux.send_keys 'C-L' lines[-1] == "kill #{pid}" end - - def test_custom_completion - tmux.send_keys '_fzf_compgen_path() { echo "\$1"; seq 10; }', :Enter - tmux.prepare - tmux.send_keys 'ls /tmp/**', :Tab, pane: 0 - tmux.until(1) { |lines| lines.item_count == 11 } - tmux.send_keys :BTab, :BTab, :BTab - tmux.until(1) { |lines| lines[-2].include? '(3)' } - tmux.send_keys :Enter - tmux.until do |lines| - tmux.send_keys 'C-L' - lines[-1] == "ls /tmp 1 2" - end - end ensure Process.kill 'KILL', pid.to_i rescue nil if pid end + + def test_custom_completion + tmux.send_keys '_fzf_compgen_path() { echo "\$1"; seq 10; }', :Enter + tmux.prepare + tmux.send_keys 'ls /tmp/**', :Tab, pane: 0 + tmux.until(1) { |lines| lines.item_count == 11 } + tmux.send_keys :BTab, :BTab, :BTab + tmux.until(1) { |lines| lines[-2].include? '(3)' } + tmux.send_keys :Enter + tmux.until do |lines| + tmux.send_keys 'C-L' + lines[-1] == "ls /tmp 1 2" + end + end + + def test_unset_completion + tmux.send_keys 'export FOO=BAR', :Enter + tmux.prepare + + # Using tmux + tmux.send_keys 'unset FOO**', :Tab, pane: 0 + tmux.until(1) { |lines| lines[-2].include? ' 1/' } + tmux.send_keys :Enter + tmux.until { |lines| lines[-1] == 'unset FOO' } + tmux.send_keys 'C-c' + + # FZF_TMUX=0 + new_shell + tmux.send_keys 'unset FOO**', :Tab + tmux.until { |lines| lines[-2].include? ' 1/' } + tmux.send_keys :Enter + tmux.until { |lines| lines[-1] == 'unset FOO' } + end end class TestBash < TestBase