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

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.

  • Wow, a whole hour and no answers yet. On SO, I would have had about ten answers by now along with a lively debate going on in the comments, some questioning my sanity and/or parentage. Oh well, guess I'll need to learn some patience :-) In any case, I've sorted it now, see below. – user9184 Jan 6 '12 at 2:51

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
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

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!)

| improve this answer | |
  • Not working in Ubuntu 13.10: $ export PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' $ xtitle TEST $ xtermcontrol --get-title Terminal $ xtermcontrol --title=TEST $ xtermcontrol --get-title Terminal EDIT: both outputs of xtermcontrol --get-title were "Terminal" and so is shown in the unity launcher as a tooltip. However, the tab title is set to current pwd – Michal Kováč Feb 11 '14 at 12:02

If you're using Gnome Terminal, also check that in Edit -> Profile Preferences -> Title and Command you have the When terminal commands set their own titles option set to Replace initial title (the default).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy