diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2017-07-30 21:51:44 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2017-07-30 21:51:44 +0900 |
commit | 376a76d1d3c39a1686b6ac7a6118c1f80af3178e (patch) | |
tree | 9ed07be4bb0eb3014dc796d1dc3e4448db0bee0c | |
parent | 1fcc07e54ed2098be9f8b8b21e4b4292f2c5ea0c (diff) |
[bash] Do not append space when path completion is cancelled
Close #990
-rw-r--r-- | shell/completion.bash | 9 | ||||
-rw-r--r-- | test/test_go.rb | 13 |
2 files changed, 18 insertions, 4 deletions
diff --git a/shell/completion.bash b/shell/completion.bash index e8c34e57..eeb5a5d9 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -151,7 +151,7 @@ __fzf_generic_path_completion() { matches=$(eval "$1 $(printf %q "$dir")" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS" $fzf $2 -q "$leftover" | while read -r item; do printf "%q$3 " "$item" done) - matches=${matches% } + [ $4 = 1 ] && matches=${matches% } if [ -n "$matches" ]; then COMPREPLY=( "$matches" ) else @@ -167,6 +167,7 @@ __fzf_generic_path_completion() { shift shift shift + shift _fzf_handle_dynamic_completion "$cmd" "$@" fi } @@ -198,7 +199,7 @@ _fzf_complete() { } _fzf_path_completion() { - __fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@" + __fzf_generic_path_completion _fzf_compgen_path "-m" "" 0 "$@" } # Deprecated. No file only completion. @@ -207,7 +208,7 @@ _fzf_file_completion() { } _fzf_dir_completion() { - __fzf_generic_path_completion _fzf_compgen_dir "" "/" "$@" + __fzf_generic_path_completion _fzf_compgen_dir "" "/" 1 "$@" } _fzf_complete_kill() { @@ -299,7 +300,7 @@ _fzf_defc() { # Anything for cmd in $a_cmds; do - _fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault" + _fzf_defc "$cmd" _fzf_path_completion "-o nospace -o default -o bashdefault" done # Directory diff --git a/test/test_go.rb b/test/test_go.rb index fa4915a1..fc3b9085 100644 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -1482,6 +1482,19 @@ module CompletionTest tmux.send_keys :Enter end + def test_completion_cancel + %w[ls cd].each do |cmd| + tmux.prepare + tmux.send_keys "#{cmd} **", :Tab + tmux.until { |lines| lines.item_count > 0 } + tmux.send_keys 'C-c' + tmux.until { |lines| lines[-1].include?('**') } + tmux.send_keys 'xoxo' + tmux.until { |lines| lines[-1].include?('**xoxo') } + tmux.send_keys 'C-u' + end + end + def test_dir_completion (1..100).each do |idx| FileUtils.mkdir_p "/tmp/fzf-test/d#{idx}" |