With Bash + iTerm2, how to name tabs?

Since you're using iterm2 on a mac, another option is you can just hit CmdI, type something, and hit ESC.

The terminal solution is a bit quicker than this, but just wanted to let you know.


I've found the following function, placed in my ~/.bashrc to be helpful:

function title {
    echo -ne "\033]0;"$*"\007"
}

Then I can call it from my bash prompt as follows:

> title I want a pony!

And my tab gets titled accordingly.


run this command to set the title of your tab or window:

export PROMPT_COMMAND='echo -ne "\033]0;YOUR NAME HERE\007"'

i've added the following to my ~/.bash_profile to always list the current directory relative to my home dir:

export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007"'

useful when you have 100 minimized terminals in your dock

hat tip to mac world