From 68343c8de405da28a8bfa9baaa2cf0bc4b94f706 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Mon, 15 Apr 2019 14:12:55 -0600 Subject: [PATCH] Allow suggestions to suggest trailing newlines Command substitution via $() trims trailing newlines so the old approach to reading everything from the fd was preventing suggestions from ending with newlines. Found the read solution here: https://stackoverflow.com/a/15184414/154703 --- src/async.zsh | 5 ++++- zsh-autosuggestions.zsh | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/async.zsh b/src/async.zsh index b038cb0..d7e9fe8 100644 --- a/src/async.zsh +++ b/src/async.zsh @@ -56,9 +56,12 @@ _zsh_autosuggest_async_request() { _zsh_autosuggest_async_response() { emulate -L zsh + local suggestion + if [[ -z "$2" || "$2" == "hup" ]]; then # Read everything from the fd and give it as a suggestion - zle autosuggest-suggest -- "$(cat <&$1)" + IFS='' read -rd '' -u $1 suggestion + zle autosuggest-suggest -- "$suggestion" # Close the fd exec {1}<&- diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index e7d9861..11ff7bd 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -769,9 +769,12 @@ _zsh_autosuggest_async_request() { _zsh_autosuggest_async_response() { emulate -L zsh + local suggestion + if [[ -z "$2" || "$2" == "hup" ]]; then # Read everything from the fd and give it as a suggestion - zle autosuggest-suggest -- "$(cat <&$1)" + IFS='' read -rd '' -u $1 suggestion + zle autosuggest-suggest -- "$suggestion" # Close the fd exec {1}<&-