smcup/rmcup: hate

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


Comments:

Wouldn't it have been simpler to just add this to your .profile?:

LESS="-X"
export LESS

Posted by Brian Utterback on April 03, 2008 at 12:25 AM MDT #

Yes, the X option of less would handle both less and by extension everything that uses less (e.g. the man command), but what about vi? What about vim, emacs?

I'm not saying that my approach is better, really. If all curses-like commands have a way of circumventing smcup/rmcup, then it would be simpler to address them individually. But instead, I decided to take the sledgehammer approach, since there has never been a situation where I didn't hate the smcup/rmcup behavior. I'd just assume never see it again.

Posted by Sam Falkner on April 03, 2008 at 03:56 AM MDT #

Post a Comment:
Comments are closed for this entry.
About

samf

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today