zsh-users
 help / color / mirror / code / Atom feed
* Number of jobs in prompt
@ 2001-10-18 21:48 Jesper Holmberg
  2001-10-18 22:01 ` Michal Politowski
  2001-10-18 22:16 ` please unscribe me Matthew Lyon
  0 siblings, 2 replies; 7+ messages in thread
From: Jesper Holmberg @ 2001-10-18 21:48 UTC (permalink / raw)
  To: zsh-users

Hi all,

question #3 from a newly-converted bash-user:

I would like to have the current number of (background) jobs displayed
in my prompt, but I can't find any variable for this. Would it still be
possible to achieve this?

TIA,

Jesper


-- 
Jesper Holmberg | tel: +33.2.29.00.21.75 |"But how can |
    jesper.holmberg@enst-bretagne.fr     | one be warm |
  ENST Br, BP 832, 29285 Brest, FRANCE   | alone?"     |


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Number of jobs in prompt
  2001-10-18 21:48 Number of jobs in prompt Jesper Holmberg
@ 2001-10-18 22:01 ` Michal Politowski
  2001-10-19  9:25   ` Jesper Holmberg
  2001-10-18 22:16 ` please unscribe me Matthew Lyon
  1 sibling, 1 reply; 7+ messages in thread
From: Michal Politowski @ 2001-10-18 22:01 UTC (permalink / raw)
  To: zsh-users

On Thu, 18 Oct 2001 23:48:53 +0200, Jesper Holmberg wrote:
> I would like to have the current number of (background) jobs displayed
> in my prompt, but I can't find any variable for this. Would it still be
> possible to achieve this?

The zsh/parameter module provides three job-related associative arrays:
jobdirs, jobtexts and jobstates.

So eg. I load the module:
zmodload -i zsh/parameter

have in my prompt the sequence:
%(1v.(bg %v%).)

and have the following precmd defined:
precmd() { psvar[1]=$#jobtexts; [[ $#jobtexts -eq 0 ]] && psvar[1]=(); }

-- 
Michal Politowski -- mpol@lab.icm.edu.pl
Warning: this is a memetically modified message


^ permalink raw reply	[flat|nested] 7+ messages in thread

* please unscribe me
  2001-10-18 21:48 Number of jobs in prompt Jesper Holmberg
  2001-10-18 22:01 ` Michal Politowski
@ 2001-10-18 22:16 ` Matthew Lyon
  1 sibling, 0 replies; 7+ messages in thread
From: Matthew Lyon @ 2001-10-18 22:16 UTC (permalink / raw)
  Cc: zsh-users

if there is a list moderator that can see this message
please unsubscribe me from this list or present me with instructions by
which I can do so.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Number of jobs in prompt
  2001-10-18 22:01 ` Michal Politowski
@ 2001-10-19  9:25   ` Jesper Holmberg
  2001-10-19  9:47     ` Oliver Kiddle
  0 siblings, 1 reply; 7+ messages in thread
From: Jesper Holmberg @ 2001-10-19  9:25 UTC (permalink / raw)
  To: zsh-users

* 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.

Jesper

-- 
          Jesper Holmberg            |"But how can |
  jesper.holmberg@enst-bretagne.fr   | one be warm |
ENST Br, BP 832, 29285 Brest, FRANCE | alone?"     |


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Number of jobs in prompt
  2001-10-19  9:25   ` Jesper Holmberg
@ 2001-10-19  9:47     ` Oliver Kiddle
  2001-10-19 16:38       ` Michal Politowski
  2001-10-22  0:17       ` Deborah Ariel Pickett
  0 siblings, 2 replies; 7+ messages in thread
From: Oliver Kiddle @ 2001-10-19  9:47 UTC (permalink / raw)
  To: Jesper Holmberg; +Cc: zsh-users

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?

Oliver


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Number of jobs in prompt
  2001-10-19  9:47     ` Oliver Kiddle
@ 2001-10-19 16:38       ` Michal Politowski
  2001-10-22  0:17       ` Deborah Ariel Pickett
  1 sibling, 0 replies; 7+ messages in thread
From: Michal Politowski @ 2001-10-19 16:38 UTC (permalink / raw)
  To: zsh-users

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
solution.

> 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@lab.icm.edu.pl
Warning: this is a memetically modified message


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Number of jobs in prompt
  2001-10-19  9:47     ` Oliver Kiddle
  2001-10-19 16:38       ` Michal Politowski
@ 2001-10-22  0:17       ` Deborah Ariel Pickett
  1 sibling, 0 replies; 7+ messages in thread
From: Deborah Ariel Pickett @ 2001-10-22  0:17 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Jesper Holmberg, zsh-users

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

I'm not convinced that this is such a helpful thing, since it is unlikely to
have exactly the right semantics for most people.  For instance, some
users are going to care only about stopped jobs, others only
backgrounded jobs, others the combined stopped and backgrounded
jobs.

(. . . plus all the other variants that I'm sure will crop up.  For
instance, I display stopped jobs (not backgrounded ones) like this:
  j[1+:vim 2-:elm 4:vim]
saying that job number 1, the current job (+) is vim, job 2, the
previous job, is elm, and so on.  I don't see how a %j prompt-thingy is
going to help with this.  But I accept that, and do some psvar-setting
stuff in precmd().)

. . just my thoughts.

-- 
Debbie Pickett http://www.csse.monash.edu.au/~debbiep debbiep@csse.monash.edu.au
"You silly sidewalker!  You know, he's getting married!" - _The Little Mermaid_


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2001-10-22  0:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-18 21:48 Number of jobs in prompt Jesper Holmberg
2001-10-18 22:01 ` Michal Politowski
2001-10-19  9:25   ` Jesper Holmberg
2001-10-19  9:47     ` Oliver Kiddle
2001-10-19 16:38       ` Michal Politowski
2001-10-22  0:17       ` Deborah Ariel Pickett
2001-10-18 22:16 ` please unscribe me Matthew Lyon

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).