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
- X-seq: zsh-users 23993
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: kill the LHS command of a pipe once the RHS command terminates
- Date: Fri, 28 Jun 2019 19:41:34 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=5IeYpmzLDVYd6sSndDXkoDafHMZrPTLDir8djr9h2CQ=; b=oEYLVxmT7Z4jd8abXnyHmk8A+jdV3fvxWjlNm5yCanLh7BuakuXUTCrQismnX02pRe RS18u0zCQo96qyV+cQKGXPX5p6VdaDZWoNC7tzKDgL3WtI1qqOqB47oaGAEPgS27eEjM 6rdOfZNb490ZrXrrAHfFk4tj13z0RpHYsW2UPpjkETUUH2JU5guChTf7BhG+K1Q83p8x zRUQbkBUiG08QilkD9e8QgArHbAxetAI/DU02pKPVJZmmv5Y59KJ4SUnDTFYAeei5mz+ BvkTvHSs1dAhinXaghmPm/6Nd/wke26hB1g7kfOVFvxs2aWDo3kuXe95zg6OAf2O3MQY yyJg==
- In-reply-to: <20190628110430.GA13790__36317.6205357135$1561719956$gmane$org@zira.vinc17.org>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mail-followup-to: zsh-users@xxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20190628110430.GA13790__36317.6205357135$1561719956$gmane$org@zira.vinc17.org>
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:
https://unix.stackexchange.com/questions/404272/how-to-exit-early-on-pipe-close?noredirect=1&lq=1
https://unix.stackexchange.com/questions/366797/grep-slow-to-exit-after-finding-match/366806#366806
https://unix.stackexchange.com/questions/416150/make-tail-f-exit-on-a-broken-pipe?noredirect=1&lq=1
So here with zsh, you can do:
zmodload zsh/system
page-and-kill-cmd() {
(echo $sysparams[pid]; "$@") | (
IFS= read -r pid
${PAGER:-less}
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.
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author