From: Vincent Lefevre <vincent@vinc17.net>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: less with subprocess
Date: Wed, 29 Sep 2021 14:51:17 +0200 [thread overview]
Message-ID: <20210929125117.GA25513@cventin.lip.ens-lyon.fr> (raw)
In-Reply-To: <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@brasslantern.com> 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@vinc17.net> - 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)
next prev parent reply other threads:[~2021-09-29 12:52 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-27 20:30 Pier Paolo Grassi
2021-09-27 20:46 ` Roman Perepelitsa
2021-09-27 21:38 ` Bart Schaefer
2021-09-27 21:48 ` Bart Schaefer
2021-09-27 22:57 ` Pier Paolo Grassi
2021-09-27 23:05 ` Bart Schaefer
2021-09-27 23:28 ` Pier Paolo Grassi
2021-09-27 23:31 ` Dominik Vogt
2021-09-28 0:41 ` Bart Schaefer
2021-09-28 0:53 ` Bart Schaefer
2021-09-28 18:52 ` Dominik Vogt
2021-09-28 19:29 ` Bart Schaefer
2021-09-29 13:02 ` Vincent Lefevre
2021-09-29 13:13 ` Pier Paolo Grassi
2021-09-29 13:26 ` Vincent Lefevre
2021-09-29 14:14 ` Bart Schaefer
2021-09-29 14:47 ` Pier Paolo Grassi
2021-09-29 17:56 ` Bart Schaefer
2021-09-30 19:22 ` Vincent Lefevre
2021-10-01 16:44 ` Bart Schaefer
2021-10-03 1:45 ` Vincent Lefevre
2021-10-03 21:41 ` Bart Schaefer
2021-09-30 19:17 ` Vincent Lefevre
2021-09-30 19:48 ` Dominik Vogt
2021-09-30 20:59 ` Pier Paolo Grassi
2021-09-30 21:03 ` Pier Paolo Grassi
2021-09-30 22:39 ` Bart Schaefer
2021-09-30 22:46 ` Pier Paolo Grassi
2021-09-30 23:46 ` Dominik Vogt
2021-10-01 0:04 ` Pier Paolo Grassi
2021-10-01 0:06 ` Pier Paolo Grassi
2021-10-01 0:31 ` Dominik Vogt
2021-10-01 1:32 ` Pier Paolo Grassi
2021-10-01 0:17 ` Dominik Vogt
2021-10-01 2:47 ` Vincent Lefevre
2021-09-29 12:51 ` Vincent Lefevre [this message]
2021-09-28 19:50 ` Pier Paolo Grassi
2021-09-27 21:38 ` Dominik Vogt
2021-09-27 22:35 ` Dominik Vogt
2021-09-27 23:03 ` Bart Schaefer
2021-09-29 12:24 ` 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=20210929125117.GA25513@cventin.lip.ens-lyon.fr \
--to=vincent@vinc17.net \
--cc=zsh-users@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).