zsh-users
 help / color / mirror / code / Atom feed
* named jobs in RPROMPT
@ 2011-09-18 14:48 Daniel
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel @ 2011-09-18 14:48 UTC (permalink / raw)
  To: zsh-users

I wanted to have a list of background jobs, with names (and some little
marker for suspended/running) in RPROMPT. I tried by turning on prompsubst
and made jobfunction which print $jobstates and then set
RPROMPT=$(jobfunction) But I get nothing, it seems jobstates is empty
during prompt generation? How can I do this?



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

* Re: named jobs in RPROMPT
  2011-09-20  7:27 ` Daniel
  2011-09-20 19:04   ` Julien Jehannet
@ 2011-09-25 17:39   ` Bart Schaefer
  1 sibling, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2011-09-25 17:39 UTC (permalink / raw)
  To: zsh-users

On Sep 20,  7:27am, Daniel wrote:
} Subject: Re: named jobs in RPROMPT
}
}   setopt promptsubst
} Now consider:
}   RPROMPT='"$jobstates"'
} and
}   my_jobs() { print $jobstates }
}   RPROMPT='"$(my_jobs)"'
} 
} The first one display the jobstates array, the second doesn't.

That's because $(...) is a subshell which has no jobs of its own.
Consider:

    sleep 10 & print $jobtexts
    print $(sleep 3 >/dev/null & print $jobtexts)
    print $jobtexts

} My idea is to have my_jobs print a very compact list of jobs, fitting in
} the right prompt.

Instead of having my_jobs print the list to stdout, which forces you
to create a sub-process whose output can be captured, just have my_jobs
assign the list directly to RPROMPT.


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

* Re: named jobs in RPROMPT
  2011-09-20  7:27 ` Daniel
@ 2011-09-20 19:04   ` Julien Jehannet
  2011-09-25 17:39   ` Bart Schaefer
  1 sibling, 0 replies; 5+ messages in thread
From: Julien Jehannet @ 2011-09-20 19:04 UTC (permalink / raw)
  To: Daniel; +Cc: zsh-users

2011/9/20 Daniel <quite@hack.org>:
> (...)
> But thanks anyway, because now I tried to minimize my code even more.
>
>  setopt promptsubst
> Now consider:
>  RPROMPT='"$jobstates"'
> and
>  my_jobs() { print $jobstates }
>  RPROMPT='"$(my_jobs)"'
>
> The first one display the jobstates array, the second doesn't. Also, running
> my_jobs from the prompt does display the array. Could this be because inside
> the function, there are no background jobs? It's in a different context, or
> something like that?
>
> My idea is to have my_jobs print a very compact list of jobs, fitting in
> the right prompt.

I would reset RPROMPT periodically instead.
Maybe something similar to :

  % my_jobs() { RPROMPT=$jobstates }
  % precmd_functions=(my_jobs)

But this is just for testing because you will certainly clutter your
rprompt this way.
Don't forget that if the line is too long, the content will not be displayed.

-- 
J u l i e n    J e h a n n e t


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

* Re: named jobs in RPROMPT
  2011-09-19 23:42 fhml
@ 2011-09-20  7:27 ` Daniel
  2011-09-20 19:04   ` Julien Jehannet
  2011-09-25 17:39   ` Bart Schaefer
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel @ 2011-09-20  7:27 UTC (permalink / raw)
  To: zsh-users

 <fhml <at> herrmann-koenigsberg.de> writes:

> 
> Hey there.
> 
> > [...] and then set
> >RPROMPT=$(jobfunction) But I get nothing, it seems jobstates is empty
> >during prompt generation?
> 
> When you do >>PROMPT=$(code)<< then 'code' gets executed and the result is
stored in PROMPT. Sometimes
> that is not what you want. What you probably want is >>PROMPT='$(code)'<<. See
the little 's? Those
> prevent 'code' from being evaluated immediately. Now the code gets evaluated
every time the PROMPT is shown.

I'm well aware of the function of single-quotes and the need for them here.
Sorry I omitted them from what was pseudo-code but didn't look like that ;)

But thanks anyway, because now I tried to minimize my code even more.

  setopt promptsubst
Now consider:
  RPROMPT='"$jobstates"'
and
  my_jobs() { print $jobstates }
  RPROMPT='"$(my_jobs)"'

The first one display the jobstates array, the second doesn't. Also, running
my_jobs from the prompt does display the array. Could this be because inside
the function, there are no background jobs? It's in a different context, or
something like that?

My idea is to have my_jobs print a very compact list of jobs, fitting in
the right prompt.
  



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

* RE: named jobs in RPROMPT
@ 2011-09-19 23:42 fhml
  2011-09-20  7:27 ` Daniel
  0 siblings, 1 reply; 5+ messages in thread
From: fhml @ 2011-09-19 23:42 UTC (permalink / raw)
  To: zsh-users

Hey there.

> [...] and then set
>RPROMPT=$(jobfunction) But I get nothing, it seems jobstates is empty
>during prompt generation?

When you do >>PROMPT=$(code)<< then 'code' gets executed and the result is stored in PROMPT. Sometimes that is not what you want. What you probably want is >>PROMPT='$(code)'<<. See the little 's? Those prevent 'code' from being evaluated immediately. Now the code gets evaluated every time the PROMPT is shown.

A simple example where 'code' is 'date'. Lets say its currently 1970-01-01 00:00:00. When you enter >>PROMPT=$(date)<<, '$(date)' gets evaluated immediately, which is the same as if you typed >>PROMPT="1970-01-01 00:00:00"<<. Of course, that will never change. If you use 's, then '$(date)' gets stored in PROMPT - just as you typed it, not evaluated. Now every time PROMPT is evaluated '$(date)' gets evaluated which gives you a brand new date every time your PROMPT is updated.

Greetings :)


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

end of thread, other threads:[~2011-09-25 17:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-18 14:48 named jobs in RPROMPT Daniel
2011-09-19 23:42 fhml
2011-09-20  7:27 ` Daniel
2011-09-20 19:04   ` Julien Jehannet
2011-09-25 17:39   ` Bart Schaefer

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