Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: access jobs information
- X-seq: zsh-users 943
- From: Andrew J Cosgriff <Andrew.Cosgriff@xxxxxxxxxxxxxxxx>
- To: Paul Lew <lew@xxxxxxxxxxxxxxxxxx>
- Subject: Re: access jobs information
- Date: Thu, 10 Jul 1997 09:12:11 +1000
- Cc: zsh-users@xxxxxxxxxxxxxxx
- In-reply-to: Paul Lew's message of "Wed, 9 Jul 1997 13:45:17 -0400"
- References: <9707091745.AA02190@xxxxxxxxxxxxxxxxxx>
[ sent to zsh-users, which seemed more appropriate than zsh-workers ]
>>>>> "Paul" == Paul Lew <lew@xxxxxxxxxxxxxxxxxx> writes:
Paul> I would like to add the current background job information to my
Paul> prompt. I could not find an interface to do this, at least:
Paul> jno=$(jobs | wc -l)
Paul> RPROMPT="$jno"
Paul> wont work. Any idea?
This is what a friend of mine hacked up a year or two ago to do a
similar sort of thing.
precmd () {
if [[ -o interactive ]]
then
# Get a list of suspended jobs to put in the command line.
# Have to use a temporary file because it's the only way
# we can run the jobs builtin and set a variable within the current
# shell - doing either of these in a subshell defeats the purpose.
# The jobs command outputs to stderr. Use the current hostname
# and process ID to ensure that there's no problems even if
# /tmp is mounted across filesystems.
builtin jobs -r >&! /tmp/jobs$HOST$$
if [[ -s /tmp/jobs$HOST$$ ]]
then
# There's at least one suspended job. Glean the job numbers from
# the file. Surround the text with the relevant description and
# proper number of spaces.
psvar[4]="`sed -n 's/^\[\([^]]*\)\].*$/\1 /p' \
< /tmp/jobs$HOST$$ | \
tr -d '\012'`"
else
# No jobs - we can skip the calls to sed and tr.
psvar[4]=""
fi
/bin/rm /tmp/jobs$HOST$$
jobs -s
fi
}
So I end up with the job numbers of any running (non-suspended) jobs
in psvar[4] (so you just put a %4v somewhere in PROMPT/RPROMPT) and
any suspended jobs are listed normally above my prompt.
Andrew
--
- Andrew J. Cosgriff - >> see X-headers >> ajc@xxxxxxxxxxxxxxxxx
LOOK!! Sullen American teens wearing MADRAS shorts and "Flock of
Seagulls" HAIRCUTS!
Messages sorted by:
Reverse Date,
Date,
Thread,
Author