Mendhak / Code

How to set the title of a tab in terminal

Both gnome-terminal in Ubuntu as well as Windows Terminal with bash allow you to set the title of the current tab youโ€™re working in. This can be useful if youโ€™re in multiple shell sessions and need a visual cue to switch between them.

Open up your ~/.bashrc file,

nano ~/.bashrc

And then add this function at the end:

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

Then save and exit (Ctrl X), and reload the file with source ~/.bashrc.

Now try setting the title.

set-title Hello World!

results

results