12

When piping command output into less, I'll scroll to the bottom of the output using the mouse and I'll find less gets stuck in forward scrolling, preventing me from scrolling back through output. This is the same behaviour as pressing F. Is there a way to unlock less from forward scroll?

Reproduce: docker-compose up | less followed by pressing F.

Kusalananda
  • 333,661

1 Answers1

11

I believe less actually says "Waiting for data... (interrupt to abort)" upon entering this mode, at least when the left-hand side of the pipeline is not producing data fast enough.

"Interrupt" means "Press Ctrl+C". This will send the INT (interrupt) signal to the less process (it sends the signal to all the processes in the foreground process group, which in your case, includes both less and docker-compose).

To avoid sending the interrupt signal to the data-producing command on the left-hand side of the pipeline, you could make that command ignore that signal completely:

( trap '' INT && some-command ) | less

In your case,

( trap '' INT && docker-compose up ) | less
Kusalananda
  • 333,661
  • 2
    My hero! Has been bothering me for weeks. It looks like less is forwarding the Interrupt to the child process, is there a way to prevent this? I'd like to be able to scroll back, but for my child process to keep on running. – retrohacker Jan 01 '17 at 21:18
  • 6
    @retrohacker ( trap '' INT && somecommand ) | less, i.e. ignore the INT signal in the sub-shell running the command. – Kusalananda Jan 01 '17 at 21:21
  • "This will send the INT (interrupt) signal to the less process." This statement is misleading. As you mention in your last paragraph, the Ctrl-C is sent to all the processes in the pipeline. The only way to prevent the generator is as you've shown by trapping the interrupt (at least the only way I know of for a simple pipeline in a shell). – Alexis Wilke Sep 29 '22 at 23:34
  • @AlexisWilke You seem to be quoting a piece of text that is not part of my answer. The sentence was an explanation of what Ctrl+C actually does; it sends an INT signal to the foreground process. Do you think it would be better to write "process group"? But that means the example kill command would be slightly misleading instead. What I wanted to say in the section is simply that Ctrl+C sends an INT signal, to establish a relation between "interrupt" and "Ctrl+C". – Kusalananda Sep 30 '22 at 06:01
  • 1
    The sentence is in your second paragraph, second sentence... All the processes in the pipeline receive the INT. I think "process group" would be better although most people probably do not know that terminology. "[by default] all processes in the pipeline receive the INT" signal may work better. – Alexis Wilke Sep 30 '22 at 16:05
  • 1
    @AlexisWilke I see it now! Thanks for guiding my eyes. Yes, you are correct, and I will try to update this to better reflect what's happening. I'm sorry for my initial confusion. – Kusalananda Sep 30 '22 at 16:35
  • 1
    @AlexisWilke I removed som irrelevant text and added something that I hope is more clarifying. Does this look ok to you? – Kusalananda Sep 30 '22 at 16:41