Degrade gracefully on systems missing zsh/system module

When using async mode, stale background processes will not be cancelled
when a new one starts. This shouldn't cause any real issues since the
processes should eventually finish and be cleaned up anyway, and
removing the handler with `zle -F` means that stale suggestions should
never be shown.
This commit is contained in:
Eric Freese 2019-06-19 13:35:54 -06:00
parent 112dd3e3c7
commit a437544cc5
2 changed files with 32 additions and 26 deletions

View file

@ -3,9 +3,9 @@
# Async # # Async #
#--------------------------------------------------------------------# #--------------------------------------------------------------------#
zmodload zsh/system
_zsh_autosuggest_async_request() { _zsh_autosuggest_async_request() {
zmodload zsh/system 2>/dev/null # For `$sysparams`
typeset -g _ZSH_AUTOSUGGEST_ASYNC_FD _ZSH_AUTOSUGGEST_CHILD_PID typeset -g _ZSH_AUTOSUGGEST_ASYNC_FD _ZSH_AUTOSUGGEST_CHILD_PID
# If we've got a pending request, cancel it # If we've got a pending request, cancel it
@ -14,17 +14,20 @@ _zsh_autosuggest_async_request() {
exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&- exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&-
zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD
# Zsh will make a new process group for the child process only if job # We won't know the pid unless the user has zsh/system module installed
# control is enabled (MONITOR option) if [[ -n "$_ZSH_AUTOSUGGEST_CHILD_PID" ]]; then
if [[ -o MONITOR ]]; then # Zsh will make a new process group for the child process only if job
# Send the signal to the process group to kill any processes that may # control is enabled (MONITOR option)
# have been forked by the suggestion strategy if [[ -o MONITOR ]]; then
kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null # Send the signal to the process group to kill any processes that may
else # have been forked by the suggestion strategy
# Kill just the child process since it wasn't placed in a new process kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
# group. If the suggestion strategy forked any child processes they may else
# be orphaned and left behind. # Kill just the child process since it wasn't placed in a new process
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null # group. If the suggestion strategy forked any child processes they may
# be orphaned and left behind.
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
fi
fi fi
fi fi

View file

@ -726,9 +726,9 @@ _zsh_autosuggest_fetch_suggestion() {
# Async # # Async #
#--------------------------------------------------------------------# #--------------------------------------------------------------------#
zmodload zsh/system
_zsh_autosuggest_async_request() { _zsh_autosuggest_async_request() {
zmodload zsh/system 2>/dev/null # For `$sysparams`
typeset -g _ZSH_AUTOSUGGEST_ASYNC_FD _ZSH_AUTOSUGGEST_CHILD_PID typeset -g _ZSH_AUTOSUGGEST_ASYNC_FD _ZSH_AUTOSUGGEST_CHILD_PID
# If we've got a pending request, cancel it # If we've got a pending request, cancel it
@ -737,17 +737,20 @@ _zsh_autosuggest_async_request() {
exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&- exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&-
zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD
# Zsh will make a new process group for the child process only if job # We won't know the pid unless the user has zsh/system module installed
# control is enabled (MONITOR option) if [[ -n "$_ZSH_AUTOSUGGEST_CHILD_PID" ]]; then
if [[ -o MONITOR ]]; then # Zsh will make a new process group for the child process only if job
# Send the signal to the process group to kill any processes that may # control is enabled (MONITOR option)
# have been forked by the suggestion strategy if [[ -o MONITOR ]]; then
kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null # Send the signal to the process group to kill any processes that may
else # have been forked by the suggestion strategy
# Kill just the child process since it wasn't placed in a new process kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
# group. If the suggestion strategy forked any child processes they may else
# be orphaned and left behind. # Kill just the child process since it wasn't placed in a new process
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null # group. If the suggestion strategy forked any child processes they may
# be orphaned and left behind.
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
fi
fi fi
fi fi