Set Terminal Tab/Window Title -- Cross-Platform!

16 Dec 2009
Posted by Jeet Sukumaran

(Several) dozens of terminal windows/tabs open at the same time? Me too. Gets confusing trying to find a particular shell sometimes. Snow Leopard introduced a feature that allows you to set a specific title for each of your Terminal windows, but to do it you have to use the mouse/GUI. Ugh.

Here is a solution that not only is mouse/GUI free, it actually works across platforms. Source (or add) the following into your .bashrc:

set_terminal_title() {
    if [[ -z $@ ]]
    then
        TERMINAL_TITLE=$PWD
    else
        TERMINAL_TITLE=$@
    fi
}
alias stt='set_terminal_title'
STANDARD_PROMPT_COMMAND='history -a ; echo -ne "\033]0;${TERMINAL_TITLE}\007"'
PROMPT_COMMAND=$STANDARD_PROMPT_COMMAND

Now, when you open a new shell, just type 'stt <TITLE-STRING>' to give a title to that window/tab for that shell session.

Makes my day.

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a biological visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.