Color xterm with Mac OS X
I’ve been putting up with a certain Mac annoyance for almost a year now, and I finally got around to finding a real solution. Mac’s Term application sets the TERM environment variable to “xterm-color.” Unfortunately, if you ssh somewhere else (say to a Solaris 8 machine) and try running vi, that TERM value is not recognized, and vi won’t start. The solution proposed on various other parts of the web is to open your Term preferences and set TERM to “xterm” instead of “xterm-color.” That makes the remote vi happy, but what a sad solution! You sacrifice color ls and vim syntax highlighting.
Tonight I did a bit of reading in ssh(1), and I saw that you could use ~/.ssh/environment to export certain environment variables. I added “TERM=xterm” to that file, and it made the remote vi happy. Note that the remote machine must permit you to pass environment values this way. You may need to change its sshd_config file to read:
PermitUserEnvironment yes
If you’re not allowed to do that, there is an alternative. Actually, it might be a better solution regardless.
A big drawback to the first approach is that you might only want to report a non-color TERM variable to certain machines. In that case, I suppose you could write a function to set and unset the variable before and after the ssh command. With a function, you also don’t need any remote sshd permissions. This code seems to work pretty well:
function sshbw {
export TERM=xterm;
ssh "$@";
export TERM=xterm-color;
}
So there you have it: color on your machine, and an acceptable TERM on the remote machine.