3.34. Determining Your Terminal's Type: tsetSeveral GNU utilities, including the two standard editors vim and emacs, need to know what kind of terminal you're using so that they can control the screen correctly. In most cases, you're working in a terminal window or on the console itself, and the system already knows those types, so you shouldn't need to help it out. But if you are connected to a Linux system via the network or a dial up line from another type of system, it might not realize that the special characters used to drive your terminal will be different. The type of your terminal is stored by your shell in something called an environment variable. Environment variables are described in more detail in Chapter 5, "The Linux Shells." You may think of them as being rather like global variables that hold strings. Before vim or emacs can work correctly, your shell's TERM environment variable must be set to your terminal type. There are several ways that this variable can be set:
If it is necessary to manually set your terminal type, the best way is to use tset from your login shell. Figure 3-45 describes how tset works.
In the following example, I found out my actual port name by using the tty utility (described in Chapter 4, "GNU Utilities for Power Users") and then examined the output from the tset command: $ tty ...display my terminal's port id. /dev/pts/1 $ tset -s ...call tset. TERM=xterm; ...shell command generated by tset. $ _ The previous example is only provided to illustrate how tset does its stuff. To actually make tset change the TERM and TERMCAP variables, which after all is the reason for using it in the first place, you must 'eval' its output. The eval shell command is described fully on page 197 in Chapter 5, "The Linux Shells." Here's a more realistic example of tset: $ set noglob ...temporarily inhibit filename expansion. $ eval `tset -s` ...evaluate output from tset. $ unset noglob ...re-enable filename expansion. $ echo $TERM ...look at the new value of TERM. network ...the terminal type that tset found. $ _ Unfortunately, the terminal type network is not very useful, as it assumes that my terminal has almost no capabilities at all. The tset command may be presented with a rule that tells it, "If the terminal type is discovered to be network, assume that the terminal is a vt100." Here is the variation of tset that does this: $ set noglob ...disable filename expansion. $ eval `tset -s -m 'network:vt100'` ...provide rule $ unset noglob ...re-enable filename expansion. $ echo $TERM ...display new TERM setting. vt100 ...this is the terminal type that tset used. $ _ If you aren't sure what type of terminal you might be on when you log in from the network, you can have tset prompt you for confirmation (or let you set something else): $ set noglob ...disable filename expansion. $ eval `tset -s -m 'network:?vt100'` ...provide rule but ask. Terminal type? [vt100] xterm ...specify xterm, hit <Enter>. $ unset noglob ...re-enable filename expansion. $ echo $TERM ...display new TERM setting. xterm ...this is the terminal type that tset used. $ _ In summary, it's wise to contain a command in your shell's startup file that calls tset to set your terminal type. Shell startup files are described in Chapter 5, "The Linux Shells." The simplest form of tset is the following: C shellsetenv TERM vt100 tset Bash/Korn shellTERM=vt100; export TERM tset The more sophisticated form of tset searches the "/etc/ttys" file for your terminal type, and should look somewhat like this: C shellset noglob eval `tset -s -m 'network:?vt100'` unset noglob Bash/Korn shelleval `tset -s -m 'network:?vt100'` |