Another useful and interesting terminal title trick

Jan 23, '03 08:23:03AM

Contributed by: uucee

Too many Terminal windows, all alike ... for every account you care about, add the following into the .tcshrc init file:

  setenv WHOAMI `whoami`
setenv HOSTNAME `hostname -s`
if ($?TERM_PROGRAM) then
if ("$TERM_PROGRAM" == "Apple_Terminal") then
alias precmd 'echo -n "^[]2;[$WHOAMI@$HOSTNAME]^G"'
endif
endif
As usual, ^[ stands for ESC, 0x1B, ^G is BELL, 0x07 [ed: enter in vi by typing Control-V then either Control-Open Bracket or Control-G.]

The reason this is a "precmd" alias is to have the title change when 'su root' and/or remote SSH sessions are suspended. On the remote SSH host, it may be necessary to substitute a "TERM" check for "TERM_PROGRAM" ("TERM_PROGRAM" isn't passed over to the remote environment by default.)

Setting the default "Window" prefs to "Active Process Name" and "Command Key" in "Window Settings..." will have the title look like (at least with Terminal.app v1.3.1):
  [root@localhost] -- emacs -- -1
PS. Don't believe KB Article 107106; Apple's interpretation of $?TERM_PROGRAM is whishful thinking under tcsh.

[Editor's note: There are a few other useful terminal titling tricks on the site as well: 1, 2, 3, 4, 5...]

Comments (8)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030123052303392