Fix completion strategy on older versions of zsh

`zpty -r` with a pattern seems to have some funky behavior on older
versions, giving unpredictable results
This commit is contained in:
Eric Freese 2018-05-24 16:45:20 -06:00
parent 973205005c
commit 949c374195
2 changed files with 10 additions and 6 deletions

View file

@ -100,9 +100,11 @@ _zsh_autosuggest_capture_completion() {
# The completion result is surrounded by null bytes, so read the # The completion result is surrounded by null bytes, so read the
# content between the first two null bytes. # content between the first two null bytes.
zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0' zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0''*'$'\0'
zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0'
completion="${line%$'\0'}" # On older versions of zsh, we sometimes get extra bytes after the
# second null byte, so trim those off the end
completion="${${${(M)line:#*$'\0'*$'\0'*}#*$'\0'}%%$'\0'*}"
# Destroy the pty # Destroy the pty
zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME

View file

@ -597,9 +597,11 @@ _zsh_autosuggest_capture_completion() {
# The completion result is surrounded by null bytes, so read the # The completion result is surrounded by null bytes, so read the
# content between the first two null bytes. # content between the first two null bytes.
zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0' zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0''*'$'\0'
zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0'
completion="${line%$'\0'}" # On older versions of zsh, we sometimes get extra bytes after the
# second null byte, so trim those off the end
completion="${${${(M)line:#*$'\0'*$'\0'*}#*$'\0'}%%$'\0'*}"
# Destroy the pty # Destroy the pty
zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME