Ubuntu – xtitle not changing title in Ubuntu 11.04

11.04gnome-terminaltitlebar

I'm trying to find a way to quickly change the title of a Gnome Terminal 2.32.1 window since I have quite a few open and I'm editing different files in each, using a compiler in one, tailing log files in others and so forth. Hence it's a pain looking for the window I want when they all say pax@pax-desktop:~.

This question led me to try xtitle but, for some reason it's not actually changing the title.

Executing xtitle xyzzy results in no visible feedback but piping it through od confirms it's outputting an escape sequence (which I'm assuming is correct, though I haven't checked in detail):

pax@pax-desktop:~/porn_dir$ xtitle xyzzy | od -xcb
0000000    5d1b    3b32    7978    7a7a    0779    5d1b    3b31    7978
        033   ]   2   ;   x   y   z   z   y  \a 033   ]   1   ;   x   y
        033 135 062 073 170 171 172 172 171 007 033 135 061 073 170 171
0000020    7a7a    0779
          z   z   y  \a
        172 172 171 007
0000024

I can go into the menu Terminal | Set Title and change it okay from there but I would much prefer a command-line solution since I can do it automatically (such as create a vi alias which sets the title to vi filename before running the editor and resets it on exit).

In the profile preferences, the initial title is set to Terminal and the When terminal commands set their own titles is set to Replace initial title. There's also only the one profile Default which is the one I'm using.

Best Answer

Turns out xtitle is working fine and changing the title. However, there's a section in the default .bashrc as follows:

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

which sets the prompt up so that it changes the title back to the usual value every time it asks the user for input.

By commenting the PS1=... line above out, the title remains set to whatever you choose.

This has the side effect of not updating the current user@host status for all terminals. To selectively enable this for just the current shell, before running xtitle use:

export PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

(Remember, you must source this in the terminal, not call/source from a script!)

Related Question