Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: less with subprocess
- X-seq: zsh-users 27175
- From: Vincent Lefevre <vincent@xxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: less with subprocess
- Date: Wed, 29 Sep 2021 14:51:17 +0200
- Archived-at: <https://zsh.org/users/27175>
- In-reply-to: <20210928185230.GA7495@gmx.de>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: Zsh Users <zsh-users@xxxxxxx>
- References: <CAP+y1xAUzYHRMKGuJR2rBNvWY4ew6+2G-PyZagZHhaqu1sfXow@mail.gmail.com> <CAN=4vMpNGbOThNtxpHcUHc=UkOJpW-zPgOOFLku=SW+s9c7+Wg@mail.gmail.com> <CAH+w=7aUMP3yw8L_Q51JU5AO1yrrCpVigkoOEagTO+iuKZ8R=A@mail.gmail.com> <CAH+w=7bCC--sF2_FGoB-B17RxGoSzcVTzRbuddqOnU_gtO=pXQ@mail.gmail.com> <CAP+y1xDdPi=DHR0KNrdCRiroC-54ev8HhfPW5O+59ap1COLBSg@mail.gmail.com> <20210927233143.GA16620@gmx.de> <CAH+w=7YOFKGfihX5794JVxcXTtS_QrAFpHAmaAotJOAYO7JMzg@mail.gmail.com> <CAH+w=7ZVWU444iL0u_RLfa-ormZTos+7M8iUQo-QqowqioFzCg@mail.gmail.com> <20210928185230.GA7495@gmx.de>
On 2021-09-28 19:52:30 +0100, Dominik Vogt wrote:
> On Mon, Sep 27, 2021 at 05:53:33PM -0700, Bart Schaefer wrote:
> > On Mon, Sep 27, 2021 at 5:41 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> > > alias -g LF='| () { cat >$1 &! less $1 ; kill $! } =(:)'
> >
> > On additional thought ... it's not really saving very much to make
> > this a global alias. An actual function
> >
> > LF () { () { cat >$1 &! less $1 ; kill $! } =(:) }
> >
> > is only two more characters to pipe into, and can also be redirected into.
>
> Both do not work for me (zsh-5.7.1, less 487). The generating
> command is killed when ctrl-c is pressed for the first time:
>
> # using the alias
> { sleep 10; i=1; while true; do echo $i; i=$[i+1]; sleep 1; done } LF
In case this can be useful, I've been using the following function
since 2019. Here, svn2log is a command that can take much time to
generate the output, so that I wanted to be about to do a Ctrl-C to
interrupt some "less" operation (e.g. after [End]) without killing
the command.
sll()
{
# The issue with "svn2log ... | less" is that after quitting the pager,
# svn2log may still take time after getting a broken pipe. One wants to
# kill it immediately by using a subshell and "kill -PIPE 0" to kill the
# process group; the PIPE signal is used instead of another one in order
# to avoid failure/killed messages from svn and/or zsh.
# The "trap '' INT" prevents Ctrl-C (useful in "less") from killing the
# subshell and the other processes of the process group, and "less" is
# run in a subshell so that the INT trap is reset. Note: avoiding the
# subshell with just "trap - INT; less" does not work as zsh implements
# WUE (but should work in shells that implement WCE).
( trap '' INT; svn2log --color ',bright_green,cyan,yellow' "$@" | \
{ (less); kill -PIPE 0 } )
# And let's avoid SIGPIPE as the exit status code.
local r=$?
return $(( r == 128 + $(kill -l PIPE) ? 0 : r ))
}
Before that, I was using "less -f <(the_command ...)" as also
mentioned in this thread, but it had some issues.
--
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author