From 25f4afb0584f61e16a9912adf74c89c5f3d87795 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sun, 31 Jul 2016 19:35:30 -0600 Subject: [PATCH] Add ZSH_AUTOSUGGEST_IGNORE_WIDGETS array --- README.md | 1 + src/bind.zsh | 14 ++++++++++++-- src/config.zsh | 10 ++++++++++ zsh-autosuggestions.zsh | 24 ++++++++++++++++++++++-- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2ce6bd5..e419134 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ This plugin works by triggering custom behavior when certain [zle widgets](http: - `ZSH_AUTOSUGGEST_ACCEPT_WIDGETS`: Widgets in this array will accept the suggestion when invoked. - `ZSH_AUTOSUGGEST_EXECUTE_WIDGETS`: Widgets in this array will execute the suggestion when invoked. - `ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS`: Widgets in this array will partially accept the suggestion when invoked. +- `ZSH_AUTOSUGGEST_IGNORE_WIDGETS`: Widgets in this array will not trigger any custom behavior. Widgets not in any of these lists will update the suggestion when invoked. diff --git a/src/bind.zsh b/src/bind.zsh index 384ae08..49763e8 100644 --- a/src/bind.zsh +++ b/src/bind.zsh @@ -47,10 +47,20 @@ _zsh_autosuggest_bind_widget() { # Map all configured widgets to the right autosuggest widgets _zsh_autosuggest_bind_widgets() { - local widget; + local widget + local ignore_widgets + + ignore_widgets=( + .\* + _\* + zle-line-\* + autosuggest-\* + $ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\* + $ZSH_AUTOSUGGEST_IGNORE_WIDGETS + ) # Find every widget we might want to bind and bind it appropriately - for widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|autosuggest-*|$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX*|zle-line-*|run-help|which-command|beep|set-local-history|yank)}; do + for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do if [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then _zsh_autosuggest_bind_widget $widget clear elif [ ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]; then diff --git a/src/config.zsh b/src/config.zsh index 4353736..f519f6f 100644 --- a/src/config.zsh +++ b/src/config.zsh @@ -48,5 +48,15 @@ ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=( vi-forward-blank-word-end ) +# Widgets that should be ignored (globbing supported but must be escaped) +ZSH_AUTOSUGGEST_IGNORE_WIDGETS=( + orig-\* + beep + run-help + set-local-history + which-command + yank +) + # Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound. ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE= diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 5ebd993..1055388 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -74,6 +74,16 @@ ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=( vi-forward-blank-word-end ) +# Widgets that should be ignored (globbing supported but must be escaped) +ZSH_AUTOSUGGEST_IGNORE_WIDGETS=( + orig-\* + beep + run-help + set-local-history + which-command + yank +) + # Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound. ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE= @@ -161,10 +171,20 @@ _zsh_autosuggest_bind_widget() { # Map all configured widgets to the right autosuggest widgets _zsh_autosuggest_bind_widgets() { - local widget; + local widget + local ignore_widgets + + ignore_widgets=( + .\* + _\* + zle-line-\* + autosuggest-\* + $ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\* + $ZSH_AUTOSUGGEST_IGNORE_WIDGETS + ) # Find every widget we might want to bind and bind it appropriately - for widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|autosuggest-*|$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX*|zle-line-*|run-help|which-command|beep|set-local-history|yank)}; do + for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do if [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then _zsh_autosuggest_bind_widget $widget clear elif [ ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]; then