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!