so I want to alow horizontal scrolling in the terminal for my custom bash command by piping the output of the command to | less -S
However, if I do this, once you exit less, the output of the command will not stay in the command line history
Is there a way to configure less to keep the output of the command in the history when you exit less?
Eg. if you look at git diff
, you can perform horizontal scrolling and then exit but the output still stays in the history in which you can then type new commands...I essentially want to emulate this for my custom bash command. Also in git diff
it performs horizontal scrolling on the spot (ie. without using a new screen) and the command line history is still visible whereas for less
it would do it in its own screen and you won't be able to see the command line history while "lessing". Would it be possible to emulate this git diff-like mechanism in less as well?
If there's any other solution without using less
feel free to throw it out there
So suppose I do this:
cat loremipsum | less -FRSX
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sed
And then I press right twice so that it scroll to the right twice. And then I press q to exit less. The output that remains on the screen will then be:
cat loremipsum | less -FRSX
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sed
ESCOC
dictum diam. Nullam quis urna ullamcorper, accumsan quam vitae, aliquet
ESCOD
nisl. Maecenas vitae lorem orci. Ut vel est erat. Cras quis sagittis sapien, ac volutpat metus.
username@server:~/httpdocs$
However in git diff when you do the same and then press q, only the last part (ie the last part of the screen where I scrolled to the right)
git diff
nisl. Maecenas vitae lorem orci. Ut vel est erat. Cras quis sagittis sapien, ac volutpat metus.
username@server:~/httpdocs$
Will remain on the screen
How do I get this to happen as well
I don't have access to anything I can run git diff
on right now, but if I read your question and comments correctly, I think the -X option to less would help. e.g.
ls -la | less -SX
This prevents less from saving and clearing the screen before displaying the output, and clearing and restoring the screen when it quits.
Update
I pulled a git workspace and figured out what git diff
is actually doing:
$ pstree -p | grep git
|-xterm(6021)---bash(6023)---sh(6104)---git(17708)---less(17709)
$ cat /proc/17709/cmdline | xargs -0 echo
less
$ cat /proc/17709/environ | xargs -0 --replace echo {} | grep LESS
LESSOPEN=|/usr/bin/lesspipe.sh %s
LESS=FRSX
$
So git diff
passes no options to less
. Instead it is setting the LESS
environment variable to FRSX
. This is the same as passing the -FRSX options to less. So, do you get what you need with -FRSX:
ls -la | less -FRSX
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With