Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: get the number of active jobs to show in the prompt?

On 2001-10-01 at 02:12 -0400, Sweth Chandramouli wrote:
> 	zsh spawns a subshell for the LHS of a pipe, rather than
> the RHS, which lets you do things like 
> $ do_something | read VAR
> 	and have VAR still be set.  That means that jobs in your
> example is being run in a subshell where there _aren't_ any background
> jobs.  The only way I can think of offhand to get the info from jobs
> would be to redirect the output of jobs to a temp file and then use that
> to build your prompt; that's not very efficient, however.  I don't know
> if there's some other way to get that info from the shell.

I picked this up from zefram, I think:

 jobs % >& /dev/null && psvar[1]="" || psvar[1]=()

Actually, what I have is this:
precmd () {
	local exitstatus=$?
	[[ $exitstatus -ge 128 ]] && psvar[1]=SIG$signals[$exitstatus-127] 
	[[ $psvar[1] = SIG ]] && psvar[1]=$exitstatus 
	jobs % >& /dev/null && psvar[2]=""  || psvar[2]=() 
[ switch PS1 depending upon $TERM, but for xterm: ]
PS1=': %2(L.%U[%L]%u.)%(?..%B{%v}%b)%(2v:+:-)%n@%m:%l(%!)%30<..<%~%#; '

The key thing is the %(2v:+:-)  --  psvar[2] was set depending upon
whether or not there are background jobs, %(2v:+:-) therefore gives a
'+' if there are background jobs, or a '-' if not.

I _really_ miss having +/- indication of background jobs when forced to
use bash.
<-------- The information went data way

Attachment: pgpzCA5VNF23U.pgp
Description: PGP signature

Messages sorted by: Reverse Date, Date, Thread, Author