4

Is there a way to ensure less clears screen on exit? The opposite of less -X.

The screen is not being cleared when I exit a man page in iTerm2, however the screen is cleared when using the default mac terminal. Does anyone have suggestions?

$LESS is set to less -R

  • Buried in the comments to one of the answers is the information that clearing the screen is not what the questioner actually wants. The questioner actually wants to restore the prior screen contents, that were there before less was run. – JdeBP Jul 24 '16 at 9:33
5

Normally less "clears the screen" (which probably refers to switching back to the normal screen from the alternate screen) when the terminal description has the appropriate escape sequence in the rmcup capability.

You would see a difference if you are using different values of TERM in the two programs. The infocmp program can show differences for the corresponding terminal descriptions.

less also attempts to clear the remainder of the screen, but that depends upon whether anything was displayed, and if the output was a terminal (in contrast to a pipe).

Aside from the terminal description, some terminal emulators make it optional whether to allow the alternate screen. You may have selected that option at some point. (I'm testing with default configuration, which works as intended).

  • To clarify, I want to switch back to the original screen and restore the previous window content history and placement after exiting the altscreen. – jpm Jul 24 '16 at 0:56
  • Sure: that's because your terminal description doesn't switch to/from alternate screen. – Thomas Dickey Jul 24 '16 at 0:56
  • By the way, some terminal emulators make it optional whether to allow the alternate screen. You may have selected that option at some point. (I'm testing with default configuration, which works as intended). – Thomas Dickey Jul 24 '16 at 1:04
  • You are correct. Unselecting Save lines to scrollback in alternate screen mode under Profiles > Terminal solved the problem. Thanks. – jpm Jul 24 '16 at 1:09
-1

Why not just clear the screen on exit?

man man; clear
  • Because even though that's what the questioner wrote, it's not what xe actually wants and the question was sloppily worded. – JdeBP Jul 24 '16 at 9:31
-1

I would suggest if 'less' fails to clear the screen that you put:

alias less='(less; clear)'

in your ~/.profile or /.bashrc.

(I am not on a linux machine to test this at the moment, but this should work in bash.)

  • 1
    That would prevent passing arguments to less. Better as less() { command less "$@"; ret=$?; clear; return "$ret"; }. Note that ~/.profile is a session customization file, not a shell customization file. In any case, neither an alias nor a function would affect man. – Stéphane Chazelas Jul 24 '16 at 9:04
  • ah, thanks. Looking back that is a much cleaner solution. – Wyatt8740 Jul 27 '16 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.