If you don't use the X Window System regularly, this node is probably not for you. If you do, chances are you regularly use Xterm style windows. One of the problems with using a large number of Xterms is that one can quickly lose track of which one is which when minimised. By default Xterms may have a window title of "Xterm", which is not exactly helpful.

There are two ways to set the Xterm title to something a little more useful. The first is from the command line, eg:

prompt% xterm -title MyWindow

Or perhaps

prompt% xterm -T myWindow

This will do for the most part. If you're like me, though, you regulary connect to a number of different machines from an Xterm window. The problem with this is that it's very easy to forget which host you're logged into in which window.

The second way is to to change the window title is to use an escape sequence.

How this is done is dependent on the shell you use. The Xterm title (and icon title) can be changed with escape sequences as follows:

ESC]0;TITLEBEL :: Set icon name and window title to TITLE
ESC]1;TITLEBEL :: Set icon name to TITLE
ESC]2;TITLEBEL :: Set window title to TITLE

(ESC is the escape character \033 and BEL is the bell character \007)

For example, the command: echo "\033]0This is the title\007"
will change the window and icon titles to "This is the title".

Once you've worked out which version works for your particular shell, you can make the window title dynamic so that it updates with "user@host: working_directory" style information. To do this, you must set the prompt string to incorporate the escape sequences. How this is done depends on your shell. Assuming that $USER and $HOST are set to the username and hostname respectively, this can be done as follows:

bash:

Place the following code into your .bashrc or .profile:

case $TERM in
   xterm*)
      PS1="\]\033[0;\u@\h: \w\007\]\\$ "
      ;;
   *)
      PS1="\u@\h: \w\\$ "
      ;;
esac

ksh:

Place the following code into your .profile:

case $TERM in
    xterm*)
        PS1='^[]0;${USER}@${HOST}: ${PWD}^G$ '
        ;;
    *)
        PS1='${USER}@${HOST}: ${PWD} '
        ;;
esac
Where ^[ is the escape character and ^G is the bell character.

tcsh:

Place the following code into your .tcshrc:

switch ($TERM)
    case "xterm*":
        alias precmd 'echo -n "\033]0;${USER}@${HOST}:$cwd\007"'
        breaksw
endsw


Adapted from the linuxdoc "How to change the title of an xterm" found at http://www.linuxdoc.org/HOWTO/mini/Xterm-Title.html

Log in or registerto write something here or to contact authors.