From: Deborah Ariel Pickett <debbiep@cs.monash.edu.au>
To: zsh-users@math.gatech.edu
Subject: Re: can i have jobs in my prompt?
Date: Sun, 14 Sep 1997 12:39:53 +1000 (EST) [thread overview]
Message-ID: <199709140239.MAA22951@molly.cs.monash.edu.au> (raw)
In-Reply-To: <199709121750.SAA07577@taos.demon.co.uk> from "Andrew Main" at Sep 12, 97 06:50:30 pm
zefram wrote:
> Matthias Kopfermann wrote:
> >i forget how many jobs are running, especially if they are in the background.
> >what would you do here?
> function precmd {
> if jobs % >& /dev/null; then
> psvar=("*")
> else
> psvar=("")
> fi
> }
Here is something I whipped up many years ago. It would only list
stopped jobs, which is what I wanted, because if a job was running I
probably already know about it. This goes inside my precmd function. A
few things to note:
- This lists jobs like this:
j[1+ 3- 4]
where job 1 is the current job and 3 is the last job and 4 is some
other job, just like 'jobs -l' prints.
- For running jobs change the -s to -r in the first line.
- this creates lots of temporary files in /tmp. If you want them to be
cleared up afterwards don't forget to have a trap on EXIT on your
interactive shell.
- older versions of zsh would print jobs to stderr, not stdout. Alter
the first line appropriately.
- gawk works in place of nawk if you don't have the latter.
- somewhere in my $PROMPT there is a %v that uses the value I put into
$psvar[4].
This mailing list flourishes on ideas. I am always looking for new
ideas of things to put in my prompt. Presently I list jobs, pwd,
folders with new mail, the status of a shat program used here at Monash,
and shell level. Anyone else got neat shell prompt stuff?
--
Debbie Pickett http://www.cs.monash.edu.au/~debbiep/ tlm@yoyo.cc.monash.edu.au
"Welcome to the food chain." - _FernGully_
# 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 -s >! /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]="j`nawk \
'/^\[/ {
if (match (\$1, /[0-9]+/)) {
jobs = jobs \" \" substr (\$1, RSTART, RLENGTH)
}
if (match (\$2, /^\+|-$/)) {
jobs = jobs \$2
}
}
END {
if (jobs != \"\") {
print \"[\" substr (jobs, 2) \"]\"
}
}' < /tmp/jobs$HOST$$` $XTTITLEBETWEEN"
else
# No jobs - we can skip the call to nawk.
psvar[4]=
fi
prev parent reply other threads:[~1997-09-14 2:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <199709121736.TAA23418@rzaix43.rrz.uni-hamburg.de>
1997-09-12 17:50 ` Andrew Main
1997-09-14 2:39 ` Deborah Ariel Pickett [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199709140239.MAA22951@molly.cs.monash.edu.au \
--to=debbiep@cs.monash.edu.au \
--cc=tlm@yoyo.cc.monash.edu.au \
--cc=zsh-users@math.gatech.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).