about summary refs log tree commit diff
path: root/Functions/Misc/getjobs
diff options
context:
space:
mode:
authorBart Schaefer <barts@users.sourceforge.net>2001-04-05 18:50:45 +0000
committerBart Schaefer <barts@users.sourceforge.net>2001-04-05 18:50:45 +0000
commit1a4194f1764f165b927e78cc730569ee9845874e (patch)
treeae4bb139ccca8933921f927871b04115a0386aa9 /Functions/Misc/getjobs
parent62e9af7ce66767f08385e43e9e216b362ee746bc (diff)
downloadzsh-1a4194f1764f165b927e78cc730569ee9845874e.tar.gz
zsh-1a4194f1764f165b927e78cc730569ee9845874e.tar.xz
zsh-1a4194f1764f165b927e78cc730569ee9845874e.zip
Write history entries for jobs resumed with fg/bg; from users/3795, plus
a couple of minor bugfixes.
Diffstat (limited to 'Functions/Misc/getjobs')
-rw-r--r--Functions/Misc/getjobs29
1 files changed, 29 insertions, 0 deletions
diff --git a/Functions/Misc/getjobs b/Functions/Misc/getjobs
new file mode 100644
index 000000000..0ac2972ff
--- /dev/null
+++ b/Functions/Misc/getjobs
@@ -0,0 +1,29 @@
+# Call this from the preexec function like so:
+#   preexec() {
+#	  getjobs "${(z)1}"
+#   }
+setopt localoptions noshwordsplit noksharrays
+local texts
+case $1 in
+    fg|bg) shift; [[ -n $1 ]] || set -- %% ;;
+    %*) ;;
+    *) return 0 ;;
+esac
+repeat $#
+do
+    # This case statement emulates jobs.c:getjob()
+    case $1 in
+	[\;\&\|]|\|\||\&\&) break ;;
+	%(|[%+])) 1=${(k)jobstates[(r)*:+:*]} ;;
+	%-) 1=${(k)jobstates[(r)*:-:*]} ;;
+	%<->) 1=${1#%} ;;
+	%[?]*) 1=${${(Ok)jobtexts[(R)*${1#%[?]}*]}[1]} ;;
+	*) 1=${${(Ok)jobtexts[(R)$1*]}[1]} ;;
+    esac
+    [[ -n $1 ]] && texts=($texts ${jobtexts[$1]})
+    shift
+done
+# Remove the "-s" below if you'd prefer that this just report
+# what jobs are being affected rather than modify the history
+(( $#texts )) && print -s ${(j:; :)texts} "$*"
+return 0