File: getjobs

package info (click to toggle)
zsh-beta 4.3.0-dev-1%2B20050424-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 18,240 kB
  • ctags: 6,564
  • sloc: ansic: 79,241; sh: 4,874; perl: 748; makefile: 676; awk: 341; sed: 16
file content (29 lines) | stat: -rw-r--r-- 827 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Call this from the preexec function like so:
#   preexec() {
#	  getjobs "${(z)2}"  # Use "${(z)1}" prior to zsh-4.0.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