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

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



Drew wrote:

> I'm tired of using my close-window shortcut to zap shells
> that still owned running programs, so I'd like my zsh prompt
> to indicate that somehow. I can't figure out how to do anything
> programmatically with the 'jobs' command (such as "jobs | wc -l"),
> so I'm lost as to how to do my prompt trick.

Looks like you've already got an answer, but there are better ways to do
this from zsh 3.1.9 onwards.

The "zsh/parameter" module defines three variables, among others:
jobdirs, jobtexts, and jobstates.  They're normal associative arrays,
which means you can do things like this:

  numberofjobs=$#jobstates

without having to invoke subshells or other yucky things you really want
to keep out of the shell prompt generation code.

If you want to count just running jobs, or suspended jobs, this appears
to work (but it probably isn't the natural way to do it; I just made up
this solution by simulated annealing):

  numberofsuspendedjobs=${(Mw)#jobstates#suspended:}

s/suspended/running/g for running jobs.

Insert "zmodload zsh/parameter" in a suitable zsh startup file (such as
.zshrc) before trying this.

-- 
Debbie Pickett http://www.csse.monash.edu.au/~debbiep debbiep@xxxxxxxxxxxxxxxxxx
  "As far as my eyes can see there are shadows surrounding me. And to those I
leave behind, I want you all to know you've always shared my darkest hours, I'll
        miss you when I go." - _Old and Wise_, The Alan Parsons Project



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