Customizing the Terminal on the Fly
You can customize the Terminal in shell scripts using escape sequences or AppleScript commands. xterm users may be familiar with using the following to set the xterm’s title:
echo '^[]2;My-Window-Title^G'
Mac OS X’s Terminal accepts this sequence as well.
Tip
^[ is the ASCII ESC character, and
^G is the ASCII BEL character. (The BEL character
is used to ring the terminal bell, but in this context, it terminates
an escape sequence.) The escape sequences described here are
ANSI escape sequences, which differ from the shell escape sequences
described earlier. ANSI escape sequences are used to manipulate a
Terminal window (such as by moving the cursor or setting the title).
Shell escape sequences are used to tell the shell to treat a
metacharacter, such as |, as a literal character
rather than an instruction to pipe standard output somewhere else.
To type the ^[ characters in
tcsh, use the key sequence Control-V Escape
(press Control-V and release, then press the Escape key). To type
^G, use Control-V Control-G. The
vi editor supports the same key sequence;
Emacs uses Control-Q instead of Control-V.
You can capture this escape sequence in a shell alias:
alias settitle 'echo -n "^[]2;\!*^G"'
Then you can change the title by issuing this command:
settitle your fancy title hereYou may want to package this as a shell script and make it available to everyone who uses your system, as shown in Example 1-3.