From b530b0c99679c00a5234c25f0adfa0d70a522900 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Tue, 24 Jan 2017 19:58:52 -0700 Subject: [PATCH] Use `zpty -r` with pattern matching to fetch suggestion --- src/async.zsh | 8 ++++---- zsh-autosuggestions.zsh | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/async.zsh b/src/async.zsh index 566a81a..1535297 100644 --- a/src/async.zsh +++ b/src/async.zsh @@ -25,10 +25,10 @@ _zsh_autosuggest_async_suggestion_server() { # First arg will be fd ready for reading # Second arg will be passed in case of error _zsh_autosuggest_async_suggestion_ready() { - # while zpty -rt $ZSH_AUTOSUGGEST_PTY_NAME suggestion 2>/dev/null; do - while read -u $_ZSH_AUTOSUGGEST_PTY_FD -d $'\0' suggestion; do - zle _autosuggest-show-suggestion "${suggestion//$'\r'$'\n'/$'\n'}" - done + local suggestion + + zpty -rt $ZSH_AUTOSUGGEST_PTY_NAME suggestion '*'$'\0' 2>/dev/null + zle _autosuggest-show-suggestion "${suggestion%$'\0'}" } # Recreate the pty to get a fresh list of history events diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index d8f1103..34c1f90 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -502,10 +502,10 @@ _zsh_autosuggest_async_suggestion_server() { # First arg will be fd ready for reading # Second arg will be passed in case of error _zsh_autosuggest_async_suggestion_ready() { - # while zpty -rt $ZSH_AUTOSUGGEST_PTY_NAME suggestion 2>/dev/null; do - while read -u $_ZSH_AUTOSUGGEST_PTY_FD -d $'\0' suggestion; do - zle _autosuggest-show-suggestion "${suggestion//$'\r'$'\n'/$'\n'}" - done + local suggestion + + zpty -rt $ZSH_AUTOSUGGEST_PTY_NAME suggestion '*'$'\0' 2>/dev/null + zle _autosuggest-show-suggestion "${suggestion%$'\0'}" } # Recreate the pty to get a fresh list of history events