My technical site

Menu

Naming Windows and Tabs in Terminal

That will turn it into your hostname (minus the domain). I’ve added the above to my standard .bashrc file on all the computers I visit via ssh.

If you want to do it yourself on the fly then

wname()
{
printf "e]2;$*a"
}

added to your .bashrc file will allow you to say “wname The New Name” at the bash prompt any time you like. If you use tabs rather than multiple windows then:

tname()
{
printf "e]1;$*a"
}

I’ll leave the function, which I define as ‘hname’, to set it back to the hostname as an exercise for the reader. Oh, and a final tip; you may notice that for the tab the string starts “e]1;” and for the window you replace the ‘1’ with a ‘2’. If you use ‘0’ then you change both the tab and the window name.

If you want to get really slick with your Terminal window name try setting it to the current directory. I now do this in my promptcommand like this:

PROMPT_COMMAND='history -a; history -n; printf "e]1;${PWD}a"'

Add that to your .profile. Now you have a directory path you can even command-click or click and drag on.