zsh-users
 help / color / mirror / code / Atom feed
* jobs numbers in prompt
@ 2008-01-16  9:24 Miek Gieben
  2008-01-16 13:31 ` Mikael Magnusson
  0 siblings, 1 reply; 4+ messages in thread
From: Miek Gieben @ 2008-01-16  9:24 UTC (permalink / raw)
  To: zsh users

[-- Attachment #1: Type: text/plain, Size: 595 bytes --]

Hello, 

In my current prompt I have a list of background jobs (if there are
any). This works like this:
    myjobs=${(pj:\,:)${(k)jobstates}}
 
And gives a list like: 1,2

Now my question, is there any possibility to include the current job
(+ sign) and previous job (- sign) in this output? Like this: 1-,2+

Is this possible? If been fighting with $jobstates all week, but I've
been unable to extract multiple fields from this array.

thanks in advance,
--
grtz,
 - Miek                               
 GPG Key ID: 3880 D0F6                           http://www.miek.nl/


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: jobs numbers in prompt
  2008-01-16  9:24 jobs numbers in prompt Miek Gieben
@ 2008-01-16 13:31 ` Mikael Magnusson
  2008-01-16 14:07   ` Miek Gieben
  0 siblings, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2008-01-16 13:31 UTC (permalink / raw)
  To: zsh users

On 16/01/2008, Miek Gieben <miek@miek.nl> wrote:
> Hello,
>
> In my current prompt I have a list of background jobs (if there are
> any). This works like this:
>     myjobs=${(pj:\,:)${(k)jobstates}}
>
> And gives a list like: 1,2
>
> Now my question, is there any possibility to include the current job
> (+ sign) and previous job (- sign) in this output? Like this: 1-,2+
>
> Is this possible? If been fighting with $jobstates all week, but I've
> been unable to extract multiple fields from this array.

Does this work?
myjobs=();for a (${(k)jobstates})
{j=$jobstates[$a];myjobs+=($a"${${(@s,:,)j}[2]}")};myjobs=${(j:,:)myjobs}

-- 
Mikael Magnusson


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

* Re: jobs numbers in prompt
  2008-01-16 13:31 ` Mikael Magnusson
@ 2008-01-16 14:07   ` Miek Gieben
  2008-01-16 18:53     ` Miek Gieben
  0 siblings, 1 reply; 4+ messages in thread
From: Miek Gieben @ 2008-01-16 14:07 UTC (permalink / raw)
  To: zsh users

[-- Attachment #1: Type: text/plain, Size: 379 bytes --]

[16 Jan, @14:31 CET, Mikael Magnusson wrote in "Re: jobs numbers in prompt ..."]
> Does this work?
> myjobs=();for a (${(k)jobstates})
> {j=$jobstates[$a];myjobs+=($a"${${(@s,:,)j}[2]}")};myjobs=${(j:,:)myjobs}

whooa! :-) it does work.

thanks!

--
grtz,
 - Miek                               
 GPG Key ID: 3880 D0F6                           http://www.miek.nl/


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: jobs numbers in prompt
  2008-01-16 14:07   ` Miek Gieben
@ 2008-01-16 18:53     ` Miek Gieben
  0 siblings, 0 replies; 4+ messages in thread
From: Miek Gieben @ 2008-01-16 18:53 UTC (permalink / raw)
  To: zsh users

[-- Attachment #1: Type: text/plain, Size: 748 bytes --]

[16 Jan, @15:07 CET, Miek Gieben wrote in "Re: jobs numbers in prompt ..."]
> [16 Jan, @14:31 CET, Mikael Magnusson wrote in "Re: jobs numbers in prompt ..."]
> > Does this work?
> > myjobs=();for a (${(k)jobstates})
> > {j=$jobstates[$a];myjobs+=($a"${${(@s,:,)j}[2]}")};myjobs=${(j:,:)myjobs}
> 
> whooa! :-) it does work.

fyi: it needed one small tweak, if you have more than 2 bg jobs:

    myjobs=()
    for a (${(k)jobstates})
    {j=$jobstates[$a];i="${${(@s,:,)j}[2]}"
    myjobs+=(a${i//[^+-]/})}
#              ^^^^^^^^^^^^^^
#        filter out anything but + or -
    myjobs=${(j:,:)myjobs}


--
grtz,
 - Miek                               
 GPG Key ID: 3880 D0F6                           http://www.miek.nl/


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

end of thread, other threads:[~2008-01-16 18:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-16  9:24 jobs numbers in prompt Miek Gieben
2008-01-16 13:31 ` Mikael Magnusson
2008-01-16 14:07   ` Miek Gieben
2008-01-16 18:53     ` Miek Gieben

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