By samf on Apr 02, 2008
Some terminals have the capability to save and restore themselves. Some programs take advantage of this, so that when you exit the program, your screen is restored to its previous state. In terms of terminfo, these capabilities are known as smcup and rmcup.
I hate this. Hate.
Let's say you want to run a command, but want to look at its man page first. The man command sends its output to your $PAGER, which is less. The less command saves/restores your screen. So, you scroll to exactly the example you want: perfect! You hit 'q' to quit... and the example is erased. Hate. Many more examples are possible, but you get the idea.
Here's how I eradicate this in my world. I use this on Solaris 10 and 11, and MacOS 10.4 and 10.5. Your mileage will probably vary, but feel free to give it a try. It's in my .zshrc file, so it's using zsh's builtin "[[" and "]]" operators, as well as "$(command)". If this fails for you, you can probably just replace "[[" with "[", "]]" with "]", and "$(command)" with "`command`".
TERMINFO="/tmp/$(id -un)-terminfo-$(uname -s)" export TERMINFO if [[ ! -d $TERMINFO ]]; then mkdir -p $TERMINFO infocmp | sed -e 's/smcup.\*,//' -e 's/rmcup.\*,//' -e '/\^[ \\t]\*$/d' \\ > $TERMINFO/fixed sed -e '1d' -e '3,$d' < $TERMINFO/fixed | grep -w $TERM >/dev/null 2>&1 if [[ $? -ne 0 ]]; then mv $TERMINFO/fixed $TERMINFO/broken sed -e "2s/\^/$TERM|/" < $TERMINFO/broken > $TERMINFO/fixed fi tic $TERMINFO/fixed fi