Skip to content

Commit d27983b

Browse files
authored
Merge pull request #447 from zsh-users/features/without-system-module
Degrade gracefully on systems missing zsh/system module
2 parents 112dd3e + a437544 commit d27983b

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

src/async.zsh

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# Async #
44
#--------------------------------------------------------------------#
55

6-
zmodload zsh/system
7-
86
_zsh_autosuggest_async_request() {
7+
zmodload zsh/system 2>/dev/null # For `$sysparams`
8+
99
typeset -g _ZSH_AUTOSUGGEST_ASYNC_FD _ZSH_AUTOSUGGEST_CHILD_PID
1010

1111
# If we've got a pending request, cancel it
@@ -14,17 +14,20 @@ _zsh_autosuggest_async_request() {
1414
exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&-
1515
zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD
1616

17-
# Zsh will make a new process group for the child process only if job
18-
# control is enabled (MONITOR option)
19-
if [[ -o MONITOR ]]; then
20-
# Send the signal to the process group to kill any processes that may
21-
# have been forked by the suggestion strategy
22-
kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
23-
else
24-
# Kill just the child process since it wasn't placed in a new process
25-
# group. If the suggestion strategy forked any child processes they may
26-
# be orphaned and left behind.
27-
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
17+
# We won't know the pid unless the user has zsh/system module installed
18+
if [[ -n "$_ZSH_AUTOSUGGEST_CHILD_PID" ]]; then
19+
# Zsh will make a new process group for the child process only if job
20+
# control is enabled (MONITOR option)
21+
if [[ -o MONITOR ]]; then
22+
# Send the signal to the process group to kill any processes that may
23+
# have been forked by the suggestion strategy
24+
kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
25+
else
26+
# Kill just the child process since it wasn't placed in a new process
27+
# group. If the suggestion strategy forked any child processes they may
28+
# be orphaned and left behind.
29+
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
30+
fi
2831
fi
2932
fi
3033

zsh-autosuggestions.zsh

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,9 @@ _zsh_autosuggest_fetch_suggestion() {
726726
# Async #
727727
#--------------------------------------------------------------------#
728728

729-
zmodload zsh/system
730-
731729
_zsh_autosuggest_async_request() {
730+
zmodload zsh/system 2>/dev/null # For `$sysparams`
731+
732732
typeset -g _ZSH_AUTOSUGGEST_ASYNC_FD _ZSH_AUTOSUGGEST_CHILD_PID
733733

734734
# If we've got a pending request, cancel it
@@ -737,17 +737,20 @@ _zsh_autosuggest_async_request() {
737737
exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&-
738738
zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD
739739

740-
# Zsh will make a new process group for the child process only if job
741-
# control is enabled (MONITOR option)
742-
if [[ -o MONITOR ]]; then
743-
# Send the signal to the process group to kill any processes that may
744-
# have been forked by the suggestion strategy
745-
kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
746-
else
747-
# Kill just the child process since it wasn't placed in a new process
748-
# group. If the suggestion strategy forked any child processes they may
749-
# be orphaned and left behind.
750-
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
740+
# We won't know the pid unless the user has zsh/system module installed
741+
if [[ -n "$_ZSH_AUTOSUGGEST_CHILD_PID" ]]; then
742+
# Zsh will make a new process group for the child process only if job
743+
# control is enabled (MONITOR option)
744+
if [[ -o MONITOR ]]; then
745+
# Send the signal to the process group to kill any processes that may
746+
# have been forked by the suggestion strategy
747+
kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
748+
else
749+
# Kill just the child process since it wasn't placed in a new process
750+
# group. If the suggestion strategy forked any child processes they may
751+
# be orphaned and left behind.
752+
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
753+
fi
751754
fi
752755
fi
753756

0 commit comments

Comments
 (0)