diff --git a/src/async.zsh b/src/async.zsh index 814a185..f1877d3 100644 --- a/src/async.zsh +++ b/src/async.zsh @@ -10,8 +10,9 @@ _zsh_autosuggest_async_request() { # If we've got a pending request, cancel it if [[ -n "$_ZSH_AUTOSUGGEST_ASYNC_FD" ]] && { true <&$_ZSH_AUTOSUGGEST_ASYNC_FD } 2>/dev/null; then - # Close the file descriptor + # Close the file descriptor and remove the handler exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&- + zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD # Zsh will make a new process group for the child process only if job # control is enabled (MONITOR option) @@ -49,10 +50,14 @@ _zsh_autosuggest_async_request() { # First arg will be fd ready for reading # Second arg will be passed in case of error _zsh_autosuggest_async_response() { - # Read everything from the fd and give it as a suggestion - zle autosuggest-suggest -- "$(cat <&$1)" + if [[ -z "$2" || "$2" == "hup" ]]; then + # Read everything from the fd and give it as a suggestion + zle autosuggest-suggest -- "$(cat <&$1)" - # Remove the handler and close the fd + # Close the fd + exec {1}<&- + fi + + # Always remove the handler zle -F "$1" - exec {1}<&- } diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 191cda1..f94859e 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -689,8 +689,9 @@ _zsh_autosuggest_async_request() { # If we've got a pending request, cancel it if [[ -n "$_ZSH_AUTOSUGGEST_ASYNC_FD" ]] && { true <&$_ZSH_AUTOSUGGEST_ASYNC_FD } 2>/dev/null; then - # Close the file descriptor + # Close the file descriptor and remove the handler exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&- + zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD # Zsh will make a new process group for the child process only if job # control is enabled (MONITOR option) @@ -728,12 +729,16 @@ _zsh_autosuggest_async_request() { # First arg will be fd ready for reading # Second arg will be passed in case of error _zsh_autosuggest_async_response() { - # Read everything from the fd and give it as a suggestion - zle autosuggest-suggest -- "$(cat <&$1)" + if [[ -z "$2" || "$2" == "hup" ]]; then + # Read everything from the fd and give it as a suggestion + zle autosuggest-suggest -- "$(cat <&$1)" - # Remove the handler and close the fd + # Close the fd + exec {1}<&- + fi + + # Always remove the handler zle -F "$1" - exec {1}<&- } #--------------------------------------------------------------------#