Skip to content

Commit

Permalink
Added ZSH version check
Browse files Browse the repository at this point in the history
  • Loading branch information
macdems committed Jul 8, 2020
1 parent 9b0b770 commit 5b210b1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
14 changes: 8 additions & 6 deletions src/bind.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ _zsh_autosuggest_bind_widget() {
# correctly. $WIDGET cannot be trusted because other plugins call
# zle without the `-w` flag (e.g. `zle self-insert` instead of
# `zle self-insert -w`).
# Preserve the ZLE_KILL | ZLE_YANK flags for builtin widgets.
# Preserve the ZLE_KILL | ZLE_YANK flags for builtin widgets for ZSH >= 5.2
eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() {
_zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@
case ${(q)widget} in
(${(j:|:)ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS}) zle -f 'kill';;
(${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS}) zle -f 'yank';;
(${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS}) zle -f 'yankbefore';;
esac
if [[ ! "${ZSH_VERSION}" < 5.2 ]]; then
case ${(q)widget} in
(${(j:|:)ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS}) zle -f 'kill';;
(${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS}) zle -f 'yank';;
(${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS}) zle -f 'yankbefore';;
esac
fi
}"

# Create the bound widget
Expand Down
3 changes: 3 additions & 0 deletions src/config.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
yank-pop
zle-\*
)
if [[ "${ZSH_VERSION}" < 5.2 ]]; then
ZSH_AUTOSUGGEST_IGNORE_WIDGETS+=(yank)
if
}

# Pty name for capturing completions for completion suggestion strategy
Expand Down
17 changes: 11 additions & 6 deletions zsh-autosuggestions.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
yank-pop
zle-\*
)
if [[ "${ZSH_VERSION}" < 5.2 ]]; then
ZSH_AUTOSUGGEST_IGNORE_WIDGETS+=(yank)
if
}

# Pty name for capturing completions for completion suggestion strategy
Expand Down Expand Up @@ -207,14 +210,16 @@ _zsh_autosuggest_bind_widget() {
# correctly. $WIDGET cannot be trusted because other plugins call
# zle without the `-w` flag (e.g. `zle self-insert` instead of
# `zle self-insert -w`).
# Preserve the ZLE_KILL | ZLE_YANK flags for builtin widgets.
# Preserve the ZLE_KILL | ZLE_YANK flags for builtin widgets for ZSH >= 5.2
eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() {
_zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@
case ${(q)widget} in
(${(j:|:)ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS}) zle -f 'kill';;
(${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS}) zle -f 'yank';;
(${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS}) zle -f 'yankbefore';;
esac
if [[ ! "${ZSH_VERSION}" < 5.2 ]]; then
case ${(q)widget} in
(${(j:|:)ZSH_AUTOSUGGEST_ZLE_KILL_WIDGETS}) zle -f 'kill';;
(${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANK_WIDGETS}) zle -f 'yank';;
(${(j:|:)ZSH_AUTOSUGGEST_ZLE_YANKBEFORE_WIDGETS}) zle -f 'yankbefore';;
esac
fi
}"

# Create the bound widget
Expand Down

0 comments on commit 5b210b1

Please sign in to comment.