902e3172c9b991ca0995a0dcd658caa29b918d8e

Author
Erik Demaine <edemaine@mit.edu>
Committer
Erik Demaine <edemaine@mit.edu>
Date

Message

Avoid error messages when there is no job

Diff

 1diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh
 2index a74ad992284bc3855b2de2ed881302c166ba81d3..59a1efb02c3ca15416b80c2c907c1de8b05dee7a 100644
 3--- a/lib/termsupport.zsh
 4+++ b/lib/termsupport.zsh
 5@@ -72,19 +72,22 @@ function omz_termsupport_preexec {
 6   local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}
 7   local LINE="${2:gs/%/%%}"
 8 
 9+  # replace fg, possibly with argument, with description from jobs
10   if [[ "$CMD" = fg ]]; then
11-    # replace fg, possibly with argument, with description from jobs
12     local JOB
13     if [[ ${(z)1} = fg ]]; then # no arguments
14-      JOB="$(jobs %%)"
15+      JOB="$(jobs %% 2>/dev/null)"
16     else # arguments
17-      JOB="$(jobs ${${(z)1}[2]})"
18+      JOB="$(jobs ${${(z)1}[2]} 2>/dev/null)"
19+    fi
20+    if [[ $? -eq 0 ]]; then
21+      JOB="${${(z)JOB}[4,$]}" # trim job number, +, pid, status
22+      title ${JOB:gs/%/%%} ${JOB:gs/%/%%}
23+      return
24     fi
25-    JOB="${${(z)JOB}[4,$]}" # trim job number, +, pid, status
26-    title ${JOB:gs/%/%%} ${JOB:gs/%/%%}
27-  else
28-    title '$CMD' '%100>...>$LINE%<<'
29   fi
30+
31+  title '$CMD' '%100>...>$LINE%<<'
32 }
33 
34 precmd_functions+=(omz_termsupport_precmd)