Naming Windows and Tabs in Terminal


Would you like to name your Terminal window?

printf "e]2;`hostname -s`a"

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

    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:

    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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s