From 949c37419544e6fab313d5139723fa315d645cab Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Thu, 24 May 2018 16:45:20 -0600 Subject: [PATCH] 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 --- src/strategies/completion.zsh | 8 +++++--- zsh-autosuggestions.zsh | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/strategies/completion.zsh b/src/strategies/completion.zsh index 0808575..a23b630 100644 --- a/src/strategies/completion.zsh +++ b/src/strategies/completion.zsh @@ -100,9 +100,11 @@ _zsh_autosuggest_capture_completion() { # The completion result is surrounded by null bytes, so read the # 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' - completion="${line%$'\0'}" + zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0''*'$'\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 zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index da10235..6683262 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -597,9 +597,11 @@ _zsh_autosuggest_capture_completion() { # The completion result is surrounded by null bytes, so read the # 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' - completion="${line%$'\0'}" + zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0''*'$'\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 zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME