Search This Blog

Thursday, May 31, 2018

How to rename terminal tab title in Ubuntu 16?

A lot of programs will overwrite the title so you can't rely on the title being fixed or not duplicated by other windows. This is especially so with remote ssh sessions in a gnome-terminal.
It still helps a lot but its not reliable enough for window managers to do matching against , so this ability has been taken out with the newest gnome-terminal, however there is still a possibility to change the title, you can do it by command.

To achieve this easily edit your ~/.bashrc file and add the following lines:

 
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 
  


With this you then can set the title of your terminal window by simply using the command set-title <name you want to set it to>. This is possible due to ANSI escape codes so any program can output them regardless of where the code is run.