GNOME Terminal: rename terminal tab title

Back in the day, you could just printf1 to set your custom title for Gnome Terminal window or tab. In the earlier versions, there even used to be a menu option to change tab titles.

However, things changed on the latest versions: first they removed the menu option, and later even the printf and echo commands stopped working.

Yesterday, I digged around the answers to "How to rename terminal tab title in gnome-terminal?" and here is what I ended up adding to my .bashrc:

set-title() { # Lazy-capture original PS1 on first use if [[ -z "${_SET_TITLE_ORIG_PS1+x}" ]]; then _SET_TITLE_ORIG_PS1="$PS1" fi if [[ "$1" == "--clear" ]]; then PS1="$_SET_TITLE_ORIG_PS1" elif [[ -z "$1" || "$1" == --* ]]; then echo "Usage: set-title \"Your Custom Title\"" echo " set-title --clear" return 1 else # Strip existing title sequence (\[\e]0;...\a\]) from the original PS1, # otherwise it would run after ours and overwrite the custom title. local base_ps1="${_SET_TITLE_ORIG_PS1#*\\a\\]}" PS1="\[\e]0;$1\a\]${base_ps1}" fi }

Add it at the very end of .bashrc to make sure nothing else is overriding the new setting.

Tested on Ubuntu 24.04.3 with GNOME Terminal Version 3.52.0 for GNOME 46.


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

Comments