diff --git a/go.mod b/go.mod index 41b40ad098b..60632549ea3 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ require ( github.com/mattn/go-isatty v0.0.14 github.com/mattn/go-runewidth v0.0.13 github.com/mattn/go-shellwords v1.0.12 - github.com/rivo/uniseg v0.2.0 + github.com/rivo/uniseg v0.4.4 github.com/saracen/walker v0.1.2 golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 diff --git a/go.sum b/go.sum index 8a875d5d263..aa7940c2e46 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,9 @@ github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4 github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk= github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/saracen/walker v0.1.2 h1:/o1TxP82n8thLvmL4GpJXduYaRmJ7qXp8u9dSlV0zmo= github.com/saracen/walker v0.1.2/go.mod h1:0oKYMsKVhSJ+ful4p/XbjvXbMgLEkLITZaxozsl4CGE= golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/shell/completion.zsh b/shell/completion.zsh index 417d03c0f4a..7ac221936cc 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -4,10 +4,11 @@ # / __/ / /_/ __/ # /_/ /___/_/ completion.zsh # -# - $FZF_TMUX (default: 0) -# - $FZF_TMUX_OPTS (default: '-d 40%') -# - $FZF_COMPLETION_TRIGGER (default: '**') -# - $FZF_COMPLETION_OPTS (default: empty) +# - $FZF_TMUX (default: 0) +# - $FZF_TMUX_OPTS (default: '-d 40%') +# - $FZF_COMPLETION_TRIGGER (default: '**') +# - $FZF_PER_CMD_COMPLETION_TRIGGERS (default: none) +# - $FZF_COMPLETION_OPTS (default: empty) # Both branches of the following `if` do the same thing -- define # __fzf_completion_options such that `eval $__fzf_completion_options` sets @@ -274,8 +275,11 @@ fzf-completion() { cmd=$(__fzf_extract_command "$LBUFFER") + # Use a per-command completion trigger if available. Otherwise, fall + # back to $FZF_COMPLETION_TRIGGER. + trigger=${FZF_PER_CMD_COMPLETION_TRIGGERS[$cmd]-${FZF_COMPLETION_TRIGGER-'**'}} + # Explicitly allow for empty trigger. - trigger=${FZF_COMPLETION_TRIGGER-'**'} [ -z "$trigger" -a ${LBUFFER[-1]} = ' ' ] && tokens+=("") # When the trigger starts with ';', it becomes a separate token diff --git a/test/test_go.rb b/test/test_go.rb index 6371e0e26b7..6c3c630fcaf 100755 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -2648,6 +2648,14 @@ def test_complete_quoted_command tmux.send_keys 'C-c' end end + + def test_per_cmd_completion_triggers + tmux.send_keys 'declare -A FZF_PER_CMD_COMPLETION_TRIGGERS', :Enter + tmux.send_keys 'FZF_PER_CMD_COMPLETION_TRIGGERS[ls]=""', :Enter + tmux.send_keys 'ls /', :Tab + tmux.until { |lines| assert_operator lines.match_count, :>, 0 } + tmux.send_keys :Enter + end end class TestFish < TestBase