Avoid clear to clear scrollback buffer of the terminal

Posted by

There is this little thing that is annoying me when doing all kind of learning and coding in the terminal. Although the option "limit scrollback to" is unchecked the terminal is not consistent in keeping this promise. This is because the command clear has it’s own opinion about this.
This article will describe how to make adjustments to the terminal settings in the shell to have clear behave as desired in this case: leave the scrollback history alone and show all.

If you type "man clear" you will see that the manual states:

clear clears your screen if this is possible, including its scrollback buffer (if the extended "E3" capability is defined).

We are going to remove this E3 capability:

First, find out the type of your terminal:

echo $TERM

For me this resulted in "xterm-256color". Whatever it outputs, remember it.

Now enter the command:

infocmp -x xterm-256color > tempfile

Where you obviously replace xterm-256color with the output from the first command. This will output the extended capabilities for this terminal type to ‘tempfile’.

Now edit this newly created file. You are looking for:

E3=\E[3J,

Find this and just remove it. The entire thing, so if it looked like:

...
Cs=\E]12;%p1%s\007, E3=\E[3J, Ms=\E]52;%p1%s;%p2%s\007, Se=\E[2 q, Ss=\E[%p1%d q,
...

It should now look like:

...
Cs=\E]12;%p1%s\007, Ms=\E]52;%p1%s;%p2%s\007, Se=\E[2 q, Ss=\E[%p1%d q,
...

Save the file. And from your terminal execute:

sudo tic -x tempfile

This will load your modified terminfo and store it. restart your terminal and clear should now no longer remove the scrollbuffer.


Source:
command line – How to stop clear from clearing scrollback buffer – Ask Ubuntu
https://askubuntu.com/questions/792453/how-to-stop-clear-from-clearing-scrollback-buffer

Leave a Reply

Your email address will not be published. Required fields are marked *