With Bash + iTerm2, how to name tabs?

In iTerm2 (Build 1.0.0.20120203), I typically open several tabs, each of which has split panes , and is about one particular theme of work, for example revision control, coding, managing files, mysql terminal work. I typically need to switch between 5 or more tabs in my work flow. It is sometimes hard to remember or tell which is which by looking at the content of the screen. I'd like to name the tabs somehow, so I can quickly tell which is which by quickly glancing. Is this possible?


Solution 1:

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.

Solution 2:

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.

Solution 3:

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

Solution 4:

I used solutions similar to the above for quite a while, but I use enough tabs that I also want them color-coded for easy visual reference. So I whipped up tabset, a utility to set the tab title, badge, and color based on the kind of work I am doing in each tab.

example

It requires node, but that is now a commonly installed platform. To install:

npm install -g iterm2-tab-set