* Re: can i have jobs in my prompt?
[not found] <199709121736.TAA23418@rzaix43.rrz.uni-hamburg.de>
@ 1997-09-12 17:50 ` Andrew Main
1997-09-14 2:39 ` Deborah Ariel Pickett
0 siblings, 1 reply; 2+ messages in thread
From: Andrew Main @ 1997-09-12 17:50 UTC (permalink / raw)
To: Matthias Kopfermann; +Cc: zsh-users
Note: I'm CCing this reply to zsh-users, as the answer is likely to be
of general interest.
Matthias Kopfermann wrote:
>i forget how many jobs are running, especially if they are in the background.
>what would you do here?
>
>-f4-7)-%{`builtin jobs`%}-
Don't use %{%}. They are used to indicate a sequence that doesn't move
the cursor, such as a colour escape sequence. Also, $() is recommended
over ``, but in any case jobs doesn't work in a subshell. A possible
approach would be to put something in precmd (a function run before each
prompt) like this:
function precmd {
if jobs % >& /dev/null; then
psvar=("*")
else
psvar=("")
fi
}
And then put "%1v" in your prompt, for example:
PROMPT="%1v> "
and this will put a * in your prompt if there are any background jobs.
You can substitute any other sequence.
I think I might start using this myself.
-zefram
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: can i have jobs in my prompt?
1997-09-12 17:50 ` can i have jobs in my prompt? Andrew Main
@ 1997-09-14 2:39 ` Deborah Ariel Pickett
0 siblings, 0 replies; 2+ messages in thread
From: Deborah Ariel Pickett @ 1997-09-14 2:39 UTC (permalink / raw)
To: zsh-users
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1997-09-14 2:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <199709121736.TAA23418@rzaix43.rrz.uni-hamburg.de>
1997-09-12 17:50 ` can i have jobs in my prompt? Andrew Main
1997-09-14 2:39 ` Deborah Ariel Pickett
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).