zsh-users
 help / color / mirror / code / Atom feed
* Problems with zsh's job control and running jobs
@ 2010-09-02 13:47 Haakon Riiser
  2010-09-02 14:30 ` Peter Stephenson
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Haakon Riiser @ 2010-09-02 13:47 UTC (permalink / raw)
  To: zsh-users

I've used zsh for years now, and since the beginning, I've been annoyed
by the way it handles running jobs.  What I want is basically to
make the "&" operator behave like "&!".

I want to be able to suspend jobs using ^Z, so I can't set NO_MONITOR.
I want zsh to warn me if I try to log out when there are suspended jobs,
so I can't set NO_CHECK_JOBS.

Is there a way to make zsh differentiate between running and
suspended jobs?  That is, make it so that CHECK_JOBS only looks for
suspended jobs, not running ones?

If not, is it possible to make "&" disown jobs by default?  I don't
want to retrain myself to use "&!" because I don't always use zsh,
and the &! syntax is not valid in other shells.

-- 
 Haakon


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

* Re: Problems with zsh's job control and running jobs
  2010-09-02 13:47 Problems with zsh's job control and running jobs Haakon Riiser
@ 2010-09-02 14:30 ` Peter Stephenson
  2010-09-02 14:37   ` Peter Stephenson
  2010-09-02 15:58   ` Bart Schaefer
  2010-09-02 14:54 ` Greg Klanderman
  2010-09-02 15:53 ` Bart Schaefer
  2 siblings, 2 replies; 9+ messages in thread
From: Peter Stephenson @ 2010-09-02 14:30 UTC (permalink / raw)
  To: zsh-users

On Thu, 2 Sep 2010 15:47:47 +0200
Haakon Riiser <haakon.riiser@fys.uio.no> wrote:
> If not, is it possible to make "&" disown jobs by default?

I got this to work.  It assumes your zsh is recent enough that (i) you have
hook functions and the add-zsh-hook function --- else you need to use
precmd (ii) "jobs" works in the left hand side of a pipeline --- else
you need to use a temporary file.

precmd_disown() {
  emulate -L zsh
  setopt extendedglob
  local job match mbegin mend

  jobs | while read job; do
    if [[ $job = \[(#b)([[:digit:]]##)\]*running* ]]; then
      disown %$match[1]
    fi
  done
}
autoload -U add-zsh-hook
add-zsh-hook precmd precmd_disown

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


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

* Re: Problems with zsh's job control and running jobs
  2010-09-02 14:30 ` Peter Stephenson
@ 2010-09-02 14:37   ` Peter Stephenson
  2010-09-02 15:04     ` Haakon Riiser
  2010-09-02 15:58   ` Bart Schaefer
  1 sibling, 1 reply; 9+ messages in thread
From: Peter Stephenson @ 2010-09-02 14:37 UTC (permalink / raw)
  To: zsh-users

On Thu, 2 Sep 2010 15:30:26 +0100
Peter Stephenson <Peter.Stephenson@csr.com> wrote:

> On Thu, 2 Sep 2010 15:47:47 +0200
> Haakon Riiser <haakon.riiser@fys.uio.no> wrote:
> > If not, is it possible to make "&" disown jobs by default?
> 
> I got this to work.

... though it does exceed the requirements a bit.  If you background a job,
it will pick it up and disown that.  That may or may not be a feature.  If
it isn't you need to look at a history to get this proposal to work.

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


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

* Re: Problems with zsh's job control and running jobs
  2010-09-02 13:47 Problems with zsh's job control and running jobs Haakon Riiser
  2010-09-02 14:30 ` Peter Stephenson
@ 2010-09-02 14:54 ` Greg Klanderman
  2010-09-02 15:53 ` Bart Schaefer
  2 siblings, 0 replies; 9+ messages in thread
From: Greg Klanderman @ 2010-09-02 14:54 UTC (permalink / raw)
  To: zsh-users


>>>>> On September 2, 2010 Haakon Riiser <haakon.riiser@fys.uio.no> wrote:

> What I want is basically to make the "&" operator behave like "&!".

See this thread from last February:

http://www.zsh.org/mla/workers/2010/msg00121.html

I never got around to replying to Bart's last post;
I'll go do that now.

Greg


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

* Re: Problems with zsh's job control and running jobs
  2010-09-02 14:37   ` Peter Stephenson
@ 2010-09-02 15:04     ` Haakon Riiser
  0 siblings, 0 replies; 9+ messages in thread
From: Haakon Riiser @ 2010-09-02 15:04 UTC (permalink / raw)
  To: zsh-users

[Peter Stephenson]

> On Thu, 2 Sep 2010 15:30:26 +0100
> Peter Stephenson <Peter.Stephenson@csr.com> wrote:
> 
> > On Thu, 2 Sep 2010 15:47:47 +0200
> > Haakon Riiser <haakon.riiser@fys.uio.no> wrote:
> > > If not, is it possible to make "&" disown jobs by default?
> > 
> > I got this to work.
> 
> ... though it does exceed the requirements a bit.  If you background a job,
> it will pick it up and disown that.  That may or may not be a feature.  If
> it isn't you need to look at a history to get this proposal to work.

Thank you very much for this code!  Not only did it solve my problem
perfectly, it also taught me about the handy hooks mechanism.
The fact that it disowns bg'd jobs is a feature in my book. :-)

-- 
 Haakon


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

* Re: Problems with zsh's job control and running jobs
  2010-09-02 13:47 Problems with zsh's job control and running jobs Haakon Riiser
  2010-09-02 14:30 ` Peter Stephenson
  2010-09-02 14:54 ` Greg Klanderman
@ 2010-09-02 15:53 ` Bart Schaefer
  2 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2010-09-02 15:53 UTC (permalink / raw)
  To: zsh-users

On Sep 2,  3:47pm, Haakon Riiser wrote:
}
} Is there a way to make zsh differentiate between running and
} suspended jobs?  That is, make it so that CHECK_JOBS only looks for
} suspended jobs, not running ones?

An answer to this is related to Greg Klanderman's reply on that other
old thread (which is on zsh-workers, so those reading only zsh-users
won't have seen it).

Disowning (&!) a job differs from merely backgrounding it in one
important respect, which is that the job becomes immune to SIGHUP
and will continue running after the shell exits.

Conversely, suspended jobs are always killed when the shell exits,
regardless of the state of NO_HUP.

So it *might* make sense for CHECK_JOBS to ignore running jobs if and
only if NO_HUP.  The question is whether the intention of CHECK_JOBS
is to warn you that you've left something unfinished, or to warn you
that something is going to be summarily terminated.

-- 


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

* Re: Problems with zsh's job control and running jobs
  2010-09-02 14:30 ` Peter Stephenson
  2010-09-02 14:37   ` Peter Stephenson
@ 2010-09-02 15:58   ` Bart Schaefer
  2010-09-04 18:03     ` John Eikenberry
  1 sibling, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2010-09-02 15:58 UTC (permalink / raw)
  To: zsh-users

On Sep 2,  3:30pm, Peter Stephenson wrote:
} Subject: Re: Problems with zsh's job control and running jobs
}
}   jobs | while read job; do
}     if [[ $job = \[(#b)([[:digit:]]##)\]*running* ]]; then
}       disown %$match[1]
}     fi
}   done

    disown %${(k)^jobstates[(R)*=running*]}

??


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

* Re: Problems with zsh's job control and running jobs
  2010-09-02 15:58   ` Bart Schaefer
@ 2010-09-04 18:03     ` John Eikenberry
  2010-09-04 20:12       ` PJ Weisberg
  0 siblings, 1 reply; 9+ messages in thread
From: John Eikenberry @ 2010-09-04 18:03 UTC (permalink / raw)
  To: zsh-users

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

Bart Schaefer wrote:

> On Sep 2,  3:30pm, Peter Stephenson wrote:
> } Subject: Re: Problems with zsh's job control and running jobs
> }
> }   jobs | while read job; do
> }     if [[ $job = \[(#b)([[:digit:]]##)\]*running* ]]; then
> }       disown %$match[1]
> }     fi
> }   done
> 
>     disown %${(k)^jobstates[(R)*=running*]}

This works but it complains at each prompt where there are no jobs to hide.

precmd_disown:disown:12: no current job

-- 

John Eikenberry
[jae@zhar.net - http://zhar.net]
[PGP public key @ http://zhar.net/jae_at_zhar_net.gpg]
______________________________________________________________
"Perfection is attained, not when no more can be added, but when no more 
 can be removed." -- Antoine de Saint-Exupery

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

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

* Re: Problems with zsh's job control and running jobs
  2010-09-04 18:03     ` John Eikenberry
@ 2010-09-04 20:12       ` PJ Weisberg
  0 siblings, 0 replies; 9+ messages in thread
From: PJ Weisberg @ 2010-09-04 20:12 UTC (permalink / raw)
  To: John Eikenberry, zsh-users

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

On Sat, Sep 4, 2010 at 11:03 AM, John Eikenberry <jae@zhar.net> wrote:

> This works but it complains at each prompt where there are no jobs to hide.
>
> precmd_disown:disown:12: no current job
>
>
Just put 2>/dev/null on the end of it.

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

end of thread, other threads:[~2010-09-04 20:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-02 13:47 Problems with zsh's job control and running jobs Haakon Riiser
2010-09-02 14:30 ` Peter Stephenson
2010-09-02 14:37   ` Peter Stephenson
2010-09-02 15:04     ` Haakon Riiser
2010-09-02 15:58   ` Bart Schaefer
2010-09-04 18:03     ` John Eikenberry
2010-09-04 20:12       ` PJ Weisberg
2010-09-02 14:54 ` Greg Klanderman
2010-09-02 15:53 ` 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).