Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: kill the LHS command of a pipe once the RHS command terminates

2019-06-28 13:04:30 +0200, Vincent Lefevre:
> With some commands I pipe the output to a pager, and when quitting
> the pager, I want the command to terminate immediately (so that it
> doesn't consume more resources) and want the shell prompt back.

See also:


So here with zsh, you can do:

zmodload zsh/system

page-and-kill-cmd() {
  (echo $sysparams[pid]; "$@") | (
    IFS= read -r pid
    kill -s PIPE $pid

And run:

page-and-kill-cmd cmd args

For a complex command, use eval:

page-and-kill-cmd eval 'seq 100; sleep 10; seq 10'

That won't work in all the cases as we're only killing one pid.


Messages sorted by: Reverse Date, Date, Thread, Author