zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: use of "less" in function and interrupt
Date: Wed, 20 Jul 2016 20:40:47 -0700	[thread overview]
Message-ID: <160720204047.ZM27592@torch.brasslantern.com> (raw)
In-Reply-To: <20160720132113.1d70a4c0@pwslap01u.europe.root.pri>

On Jul 20,  1:21pm, Peter Stephenson wrote:
} Subject: Re: use of "less" in function and interrupt
}
} On Wed, 20 Jul 2016 13:36:33 +0200
} Vincent Lefevre <vincent@vinc17.net> wrote:
} > With zsh 5.2, if I type:
} > 
} > zira% tless() { less "$@"; }
} > zira% sleep 5 | tless
} > 
} > then "less" is left stopped in background after I type a key.

After you type ^C, you mean?

} Interestingly, I can get this to happen with
} 
} sleep 5 | { less }

In both cases it works as expected provided that "sleep 5" has exited,
so you have to interrupt the sleep.

} but not
} 
} sleep 5 | ( less )
} 
} I'm not sure what that says about job control, which I've never really
} understood, but the two cases should be very close as in the second the
} shell knows it's about to exit and should exec less without an extra
} fork.

I believe the difference is that in both the functin case and the curly
brackets case you have a "current shell job" at the tail of the pipeline;
"less" is a subjob of that current shell job.  In the other cases you
have a true external job at the end of the pipeline; you're correct that
the subshell exec's less, so it's equivalent to piping directly to less.

} I'm guessing that in the failing cases less is somehow being
} detached from the terminal while in the other cases it isn't and, when
} you quit less, normal service is resumed.

Pretty much, yes.  I think what's happening is that the "current shell
job" is noticing that a ^C was delivered and therefore stops waiting
for its subjobs, not noticing that that "less" has ignored the signal
and continued on anyway.

Probably there's some point where the one last wait is needed, within
the cleanup of jobs in the current shell, to make sure that all the
subjobs really did go away.  I suspect this to be related to the
breakup of errflag into ERRFLAG_ERROR and ERRFLAG_INT.


  reply	other threads:[~2016-07-21  3:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-20 11:36 Vincent Lefevre
2016-07-20 12:21 ` Peter Stephenson
2016-07-21  3:40   ` Bart Schaefer [this message]
2016-07-21 18:51     ` Vincent Lefevre
2016-07-23 17:02     ` Bart Schaefer
2016-07-25 13:40       ` Vincent Lefevre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=160720204047.ZM27592@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).