mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-11-18 09:51:06 +01:00
Merge pull request #487 from zsh-users/features/completion-ignore
Allow skipping completion suggestions when buffer matches a pattern
This commit is contained in:
commit
cf445d08b0
4 changed files with 42 additions and 1 deletions
|
@ -93,6 +93,12 @@ Set `ZSH_AUTOSUGGEST_HISTORY_IGNORE` to a glob pattern to prevent offering sugge
|
|||
|
||||
**Note:** This only affects the `history` and `match_prev_cmd` suggestion strategies.
|
||||
|
||||
### Skipping completion suggestions for certain cases
|
||||
|
||||
Set `ZSH_AUTOSUGGEST_COMPLETION_IGNORE` to a glob pattern to prevent offering completion suggestions when the buffer matches that pattern. For example, set it to `"git *"` to disable completion suggestions for git subcommands.
|
||||
|
||||
**Note:** This only affects the `completion` suggestion strategy.
|
||||
|
||||
|
||||
### Key Bindings
|
||||
|
||||
|
|
|
@ -5,7 +5,9 @@ describe 'the `completion` suggestion strategy' do
|
|||
session.
|
||||
run_command('autoload compinit && compinit').
|
||||
run_command('_foo() { compadd bar; compadd bat }').
|
||||
run_command('compdef _foo baz')
|
||||
run_command('_num() { compadd two; compadd three }').
|
||||
run_command('compdef _foo baz').
|
||||
run_command('compdef _num one')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -37,6 +39,21 @@ describe 'the `completion` suggestion strategy' do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when ZSH_AUTOSUGGEST_COMPLETION_IGNORE is set to a pattern' do
|
||||
let(:options) { ['ZSH_AUTOSUGGEST_STRATEGY=completion', 'ZSH_AUTOSUGGEST_COMPLETION_IGNORE="one *"'] }
|
||||
|
||||
it 'makes suggestions when the buffer does not match the pattern' do
|
||||
session.send_string('baz ')
|
||||
wait_for { session.content }.to eq('baz bar')
|
||||
end
|
||||
|
||||
it 'does not make suggestions when the buffer matches the pattern' do
|
||||
session.send_string('one t')
|
||||
sleep 1
|
||||
expect(session.content).to eq('one t')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when async mode is enabled' do
|
||||
let(:options) { ['ZSH_AUTOSUGGEST_USE_ASYNC=true', 'ZSH_AUTOSUGGEST_STRATEGY=completion'] }
|
||||
|
||||
|
|
|
@ -96,6 +96,12 @@ _zsh_autosuggest_capture_completion_async() {
|
|||
}
|
||||
|
||||
_zsh_autosuggest_strategy_completion() {
|
||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||
emulate -L zsh
|
||||
|
||||
# Enable extended glob for completion ignore pattern
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
typeset -g suggestion
|
||||
local line REPLY
|
||||
|
||||
|
@ -105,6 +111,9 @@ _zsh_autosuggest_strategy_completion() {
|
|||
# Exit if we don't have zpty
|
||||
zmodload zsh/zpty 2>/dev/null || return
|
||||
|
||||
# Exit if our search string matches the ignore pattern
|
||||
[[ -n "$ZSH_AUTOSUGGEST_COMPLETION_IGNORE" ]] && [[ "$1" == $~ZSH_AUTOSUGGEST_COMPLETION_IGNORE ]] && return
|
||||
|
||||
# Zle will be inactive if we are in async mode
|
||||
if zle; then
|
||||
zpty $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME _zsh_autosuggest_capture_completion_sync
|
||||
|
|
|
@ -592,6 +592,12 @@ _zsh_autosuggest_capture_completion_async() {
|
|||
}
|
||||
|
||||
_zsh_autosuggest_strategy_completion() {
|
||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||
emulate -L zsh
|
||||
|
||||
# Enable extended glob for completion ignore pattern
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
typeset -g suggestion
|
||||
local line REPLY
|
||||
|
||||
|
@ -601,6 +607,9 @@ _zsh_autosuggest_strategy_completion() {
|
|||
# Exit if we don't have zpty
|
||||
zmodload zsh/zpty 2>/dev/null || return
|
||||
|
||||
# Exit if our search string matches the ignore pattern
|
||||
[[ -n "$ZSH_AUTOSUGGEST_COMPLETION_IGNORE" ]] && [[ "$1" == $~ZSH_AUTOSUGGEST_COMPLETION_IGNORE ]] && return
|
||||
|
||||
# Zle will be inactive if we are in async mode
|
||||
if zle; then
|
||||
zpty $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME _zsh_autosuggest_capture_completion_sync
|
||||
|
|
Loading…
Reference in a new issue