Using escape sequences to change the title bar

You can specify the text that is displayed in the title bar of an Interix terminal window. This text, which is often the current directory or currently executing command, can be up to 255 characters long.

To place text in the title bar, use the escape sequence:

\0033]0;text\a

where \0033 is the octal code for the escape character, text is the title-bar text, and \a is the alert-escape sequence. You can also send the escape sequence by using the command CTRL+V, ESC, and the alert sequence by using CTRL+V, CTRL+G. To echo a string to the terminal, type:

echo

If your terminal is anything other than an Interix console window or an xterm window, you should not use escape codes to display commands in the title bar.

For example, to set the terminal title bar to Telnet link to Saturn, type:

echo "\0033]0;Telnet link to Saturn\a"

If you want the current directory to appear in the title bar, you can create the following script in the Korn shell and save it in .profile or .environ.

_cd  () {
   if test $# -eq 0
   then
	cd
	echo "\033];$PWD\a"
   elif cd "$*"
   then
	echo "\033];$PWD\a"
   fi
}
alias cd="_cd"

The alias ensures that when you type cd, the _cd function is executed. The function states that if the cd command succeeds, the terminal title bar should be set to the value of the current working directory stored in the PWD variable.

If you want the command you are currently using in the Korn shell to appear in the title bar, type the following:

set -o cmd_intitle

In the C shell, the variable showcmd controls the display of the command in the title bar. If showcmd is set, all commands that are not built in will be displayed:

set showcmd

If a command executes quickly, you might not see it in the title bar.