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

Re: Number of jobs in prompt

On Fri, 19 Oct 2001 10:47:50 +0100, Oliver Kiddle wrote:
> Jesper Holmberg wrote:
> > 
> > * On Fri Oct 19, Michal Politowski wrote:
> > > have in my prompt the sequence:
> > > %(1v.(bg %v%).)
> > >
> > > and have the following precmd defined:
> > > precmd() { psvar[1]=$#jobtexts; [[ $#jobtexts -eq 0 ]] && psvar[1]=(); }
> > 
> > I don't think I understand this solution, and my initial attempts to
> > implement it have been unsuccessful. But I'll take a look at it during
> > the weekend. Thanks.
> An easier solution to understand would be to use setopt promptsubst and include '$#jobtexts' in your PS1 parameter. $#jobtexts expands to the number of elements in the jobtexts array so will give you the number of jobs.

Yes. I guess I should have written it explicitely instead of presenting my

> Michal's solution is a bit more clever as it only puts the number of jobs in the prompt if there are more than zero jobs. To do this he uses a ternary expression to test the contents of the psvar array which is set to $#jobtexts from the precmd() function.

Actually with promptsubst I could use
${${${#jobtexts}:#0}/?*/(bg $#jobtexts)}
which looks even more unparsable than the original, but leaves psvar and
precmd free.
I even think I'll make the change.

> Would it be a good idea to add a %j prompt expansion and j test character to prompt expansion to make this easier?

I can say, I'd use it instead of my inventions.

Michal Politowski -- mpol@xxxxxxxxxxxxxx
Warning: this is a memetically modified message

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