From 4869a757c8b641007a405e6937db13e72eaca83d Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Sun, 1 Jul 2018 20:55:53 -0600 Subject: [PATCH] Ensure we always destroy the zpty If running in sync mode and a completion takes a long time, the user can ^C out of it. Without this patch, the pty will not be destroyed in this case and the next time we go to create it, it will fail, making the shell unusable. --- src/strategies/completion.zsh | 20 +++++++++++--------- zsh-autosuggestions.zsh | 20 +++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/strategies/completion.zsh b/src/strategies/completion.zsh index 2f162dc..9b6341c 100644 --- a/src/strategies/completion.zsh +++ b/src/strategies/completion.zsh @@ -86,14 +86,16 @@ _zsh_autosuggest_strategy_completion() { zpty -w $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME $'\t' fi - # 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''*'$'\0' + { + # 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''*'$'\0' - # On older versions of zsh, we sometimes get extra bytes after the - # second null byte, so trim those off the end - suggestion="${${${(M)line:#*$'\0'*$'\0'*}#*$'\0'}%%$'\0'*}" - - # Destroy the pty - zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME + # On older versions of zsh, we sometimes get extra bytes after the + # second null byte, so trim those off the end + suggestion="${${${(M)line:#*$'\0'*$'\0'*}#*$'\0'}%%$'\0'*}" + } always { + # Destroy the pty + zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME + } } diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 7a612f9..68f1bb1 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -556,16 +556,18 @@ _zsh_autosuggest_strategy_completion() { zpty -w $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME $'\t' fi - # 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''*'$'\0' + { + # 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''*'$'\0' - # On older versions of zsh, we sometimes get extra bytes after the - # second null byte, so trim those off the end - suggestion="${${${(M)line:#*$'\0'*$'\0'*}#*$'\0'}%%$'\0'*}" - - # Destroy the pty - zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME + # On older versions of zsh, we sometimes get extra bytes after the + # second null byte, so trim those off the end + suggestion="${${${(M)line:#*$'\0'*$'\0'*}#*$'\0'}%%$'\0'*}" + } always { + # Destroy the pty + zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME + } } #--------------------------------------------------------------------#