Pages

Thursday, June 2, 2011

Change Terminal Title With Bash

Programmatically change the title of the active Terminal window from the Bash Shell. This can be useful for a variety of things, I like to alias the names of the servers I connect to in SSH to simply the server's name. I also change the title of the Terminal window in the alias so I can keep track of which terminal window is connected to what server. If you open multiple tabs in Terminal the window title will also appear in the tab.

Changing the Terminal window is very straight forward simply type: echo -n -e "\033]0;WINDOW_TITLE\007" where WINDOW_TITLE is the string you want the title of the window to be. Changing the window title isn't permanent, and you can execute the command several times and only the most recent change will be reflected.

It is also possible to put variables into the window title, for example: echo -n -e "\033]0;$HOSTNAME\007" will change the title of the window to the name of the current host.

No comments:

Post a Comment