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

Re: Number of jobs in prompt

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.

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.

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


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