summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2016-02-16 12:32:05 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2016-02-16 12:32:05 +0900
commita568120e42a86bc37b87ae6facab91f7b35f988e (patch)
tree30f9d8e3df8288d1d17e5e67274f38cc3c2d5cbc
parente57182c6580d887c85cf0ec0f9d0032671dd585a (diff)
Fix #494 - _fzf_complete hangs on zsh when not using tmux pane
-rw-r--r--shell/completion.zsh13
-rw-r--r--test/test_go.rb49
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