zsh-users
 help / color / mirror / code / Atom feed
From: Pier Paolo Grassi <pierpaolog@gmail.com>
To: dominik.vogt@gmx.de, Zsh-Users List <zsh-users@zsh.org>
Subject: Re: less with subprocess
Date: Tue, 28 Sep 2021 21:50:14 +0200	[thread overview]
Message-ID: <CAP+y1xAsr=cCfLguyy7tzd_XMzU2wpkN2pYm4tM4yNf4kQsGMQ@mail.gmail.com> (raw)
In-Reply-To: <20210927233143.GA16620@gmx.de>

[-- Attachment #1: Type: text/plain, Size: 4201 bytes --]

Hello:

>2) You want "ctrl-c" to stop less from reading input and go into
>  "view" mode, then press "F" to go back to "listening" mode?  If
> so, what are these experiments with "SIGPIPE" trying to do?

this I have no problem obtaining with:

less -f <(long lived find command)

>1) less does not react to SIGINT before it receives any input.
>  Actually, less (v487) does not react to SIGINT before it
>  receives a full screen of input.

Yes I was looking for help about this issue. I understand now from
yesterday's experiments and the help from the ml that less is the reason I
can't kill the pipe when I press ctrl-c, since it eats the sigint before it
has a full screen of input, as you pointed out. I would have liked to be
able to trap the sigint and send a sigpipe to the session, thus killing
both less and the long lived no-ouput-still find command. But it seems to
me this is unachievable, since less must be the foreground process, and
thus, if it eats the sigint, nothing can be done about it.
One experiment seemed for a moment a good solution, using unbuffer from
expect package on less, but the less loses the ability to process
interactive input.
So it seems that ctrl-z, kill % is the only solution that can be applied
when less "hangs" waiting for more input and ignores ctrl-c, without
resorting to using kill from other terminals.
The solution mentioned with =() I do use sometimes, but this was more of a
"what about doing everything in memory" challenge; about the solutions with
a pipe instead of process substitution I already investigated and I wasn't
able to make it work, in particular I wasn't able to make the solutions
with the trap on the first command to work, such as:

( trap "" INT; sleep 10; i=1; while true; do echo $i; i=$[i+1]; sleep 1;
done ) | less

and the likes, I still get the
lines 1--1...skipping...

output and the need to use ctrl-z

Pier Paolo Grassi


Il giorno mar 28 set 2021 alle ore 01:34 Dominik Vogt <dominik.vogt@gmx.de>
ha scritto:

> On Tue, Sep 28, 2021 at 12:57:02AM +0200, Pier Paolo Grassi wrote:
> > I am trying some variations based on suggestions from the page Roman
> linked:
> >
> > (trap 'kill -PIPE 0' INT; less -f -+F <(eval "sleep 100" ))
> > /proc/self/fd/11 lines 1--1...skipping...
> > /proc/self/fd/11 lines 1--1...skipping...
> > /proc/self/fd/11 lines 1--1...skipping...
> > /proc/self/fd/11 lines 1--1...skipping...
> > /proc/self/fd/11 lines 1--1...skipping...
> > /proc/self/fd/11 lines 1--1...skipping...
> >
> > the "skipping lines" is what is printed, I assume by less, when I press
> > ctrl-c
> > I can confirm that using ctrl-z and kill % is able to successfully get
> rid
> > of the process, but it seems kind of an emergency measure to me, not
> what I
> > would like to be my routine.
> > It seems to me that less is eating the ctrl-c, so the trap is never
> called,
>
> It's still not clear to me what you're trying to accomplish.  You
> mentioned two issues:
>
> 1) less does not react to SIGINT before it receives any input.
>    Actually, less (v487) does not react to SIGINT before it
>    receives a full screen of input.  A workaround is to print some
>    dummy input before the real command.  Something like
>
>      less -f <( repeat $LINES; echo ""; ls -lR / )
>
> 2) You want "ctrl-c" to stop less from reading input and go into
>    "view" mode, then press "F" to go back to "listening" mode?  If
>    so, what are these experiments with "SIGPIPE" trying to do?
>
>    If you want less to work on the command output like it would
>    work on a growing file, why don't you just *write* that output
>    to a file and run less on that?
>
>      alias -g LF="> $HOME/tmp/less-input.$$ & less
> $HOME/tmp/less-input.$$; kill %; rm $HOME/tmp/less-input.$$"
>
>    Run it with
>
>      ls -lR / 2> /dev/null LF
>                           ^^^^
>
>    The global alias saves you the effort of typing all that stuff
>    with the tempfile and less after the command.
>
>    (You really want to use a private path for the tempfiles
>    because the alias would be vulnerable to symlink attacks when used
>    in a publicly writeable directory.)
>
> Ciao
>
> Dominik ^_^  ^_^
>
> --
>
> Dominik Vogt
>
>

[-- Attachment #2: Type: text/html, Size: 5611 bytes --]

  parent reply	other threads:[~2021-09-28 19:51 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
2021-09-28 19:50           ` Pier Paolo Grassi [this message]
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='CAP+y1xAsr=cCfLguyy7tzd_XMzU2wpkN2pYm4tM4yNf4kQsGMQ@mail.gmail.com' \
    --to=pierpaolog@gmail.com \
    --cc=dominik.vogt@gmx.de \
    --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).