Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there a way to set the gnome-terminal title from within the terminal itself without having to right click on the tab. Something like:

active-terminal --title "Foo"

There was a related question previously with an answer that almost lets you do this: How to change Gnome-Terminal title? but that doesn't set the gnome-terminal tab title only the window title.

share|improve this question

1 Answer

up vote 9 down vote accepted

The following will set the terminal's title to "New terminal title":

echo -en "\033]0;New terminal title\a"

You will probably also have to change the environment variable PS1, though, otherwise your changes won't show up because it will reset the title after each command. The default .bashrc that ships with Ubuntu contains the following line:

PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

... the "\e]0;" code tells it to write everything up to the "\a" in both the title and icon-name properties. You need to remove that and set it to something like this (i.e. without the \e]0; code):

PS1="${debian_chroot:+($debian_chroot)}\u@\h \w\a$ "

Then any changes that you make with the above echo command will change the terminal title. If you're going to use this a lot, you can throw it into a function in your ~/.bashrc file:

set_term_title(){
   echo -en "\033]0;$1\a"
}

Then you can just set the title to "kittens" from the command line by doing:

set_term_title kittens

(You have to restart bash though after editing .bashrc, for your changes to take effect)

share|improve this answer
Oh great! I would never have figured that out. I changed it so set_term_title exports the updated PS1 variable, before setting the title since I'm sure I'd like to keep the default behavior unless I'm explicitly setting the title. :) – Kit Sunde Mar 19 '11 at 13:49
I have updated my /etc/bash.bashrc with the PS1 you specified, but after setting the title, using the command also from your answer, nothing updates. I am using Ubuntu 11.04. Anything changed? – Sander Jun 7 '11 at 6:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.