Used to be able to right click on the tab and change the title. Not sure how to do this anymore. Just upgraded to Fedora 21.

EDIT: I have switched from gnome-terminal to ROXterm

up vote 77 down vote accepted

Create a function in ~/.bashrc:

function set-title() {
  if [[ -z "$ORIG" ]]; then
    ORIG=$PS1
  fi
  TITLE="\[\e]2;$*\a\]"
  PS1=${ORIG}${TITLE}
}

Then use your new command to set the terminal title. It works with spaces in the name too

set-title my new tab title

It is possible to subsequently use set-title again (original PS1 is preserved as ORIG).

  • 6
    That works in a local way! But when you use ssh the title changes to the remote hostname – Hanynowsky May 6 '15 at 15:23
  • 1
    On Fedora 21, Bash 3.14.3, this caused wraparound issues with long terminal commands. The TITLE variable should be wrapped by \[ and \] so it isn't included in length/wraparound calculation. i.e. TITLE="\[\e]2;$@\a\]". I'm submitting that as an edit to this answer. – kdbanman May 8 '15 at 15:26
  • 1
    Nice, I can confirm the weird wraparound and that your fix works. – penner May 8 '15 at 15:55
  • 2
    In TITLE="\[\e]2;$@\a\]" youre assigning an array to a string, use * instead of @ to concatenate. So TITLE="\[\e]2;$*\a\]" is right, works well and does not throw errors when checking with debugging tools like shellcheck. Sugested edit for answer. – Videonauth Apr 27 '16 at 2:25
  • Doesn't seem to work with zsh -- I get $ [\e]2;my new tab title\a\] as the prompt. – Wilfred Hughes Sep 29 '16 at 2:46

The user title code was removed1 from gnome-terminal 3.14. To set the title, you could use an escape sequence:

printf "\e]2;YOUR TITLE GOES HERE\a"

or e.g. with bash:

PROMPT_COMMAND='echo -ne "\033]0;YOUR TITLE GOES HERE\007"'

1: see gnome bug 724110 and gnome bug 740188.

  • 6
    Thanks for a link to the discussions. I guess the answer to this was NO. A funny quote from one of the links: "modern users do not use terminals". LOL. – penner Jan 5 '15 at 19:12
  • This doesn't work for me: Fedora 21, Bash 3.14.3. – kdbanman May 8 '15 at 15:31
  • It works on fc22 also.. – Balaji Perumal Jan 8 '16 at 5:47
  • works with centos 7 – Abid Rahman K Jul 28 '16 at 6:26
  • 2
    Apparently, it's coming back... "Yeah sorry, the --title option is restored in GNOME 3.20 (March 2016 release), which we released half a year ago, but Ubuntu 16.04 shipped with GNOME 3.18 (September 2015 release), which had removed this option." Michael Catanzaro's 2016-09-01 18:41:45 UTC comment #31 (from second bug, 740188) – sage Jan 12 '17 at 22:10

New versions of gnome-terminal just thrown away most helpful professional features. :-(

I have tried to setup and get an older version of gnome-terminal running and also compared alternatives.

If terminator is too exotic for you, the mate-terminal is a great option! It is a fork of gnome-terminal and just keeps all the good features:

  • you can open multiple tabs from the command line giving them different titles

    mate-terminal --tab -t "aaa" --tab -t "bbb" --tab -t "ccc"
    
  • you can set up a keyboard shortcut (I use Ctrl+Shift-i) to set a title

  • Guake is also not a bad variant – Bunyk Jan 12 at 10:00

When you run a resident program like top or ssh, the tab is properly labeled.

gnome-terminal --tab -e top -t "aaa" --tab -e top -t "bbb" 

put this in .bashrc:

function title() { 
  p1='echo -ne "\033]0;' 
  p2='\007"'
  PROMPT_COMMAND=$p1$@$p2 
  p1= 
  p2=
}

As an expansion onto @Weston Ganger's answer, if you want to automatically set a title upon opening a new Gnome terminal, then add this to the bottom of your ~/.bashrc:

if [ ! -z "$SET_TITLE" ]; then
    set-title $SET_TITLE;
    export SET_TITLE=;
fi

Then launch a terminal like:

gnome-terminal --tab -e 'bash -c "export SET_TITLE=\"my title\"; bash -i"'

and it will automatically run set-title to apply the title.

If you're using Ubuntu 16.04 you may need to:

PS1=$
PROMPT_COMMAND=
echo -en "\033]0;New title\a"

I list this an more info about it at link.

  • Why shouldn't I cross post in this case? – Zach Pfeffer Jun 11 at 12:05

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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