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?
17 Answers
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.
- 2,786
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.
- 3,341
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
- 1,127
- 9
- 8
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.
It requires node, but that is now a commonly installed platform. To install:
npm install -g iterm2-tab-set
- 401
Add this function to your ~/.bash_profile file and it should work.
function title ()
{
TITLE=$*;
export PROMPT_COMMAND='echo -ne "\033]0;$TITLE\007"'
}
- 113
- 171
I like this one:
#setup terminal tab title
function title {
if [ "$1" ]
then
unset PROMPT_COMMAND
echo -ne "\033]0;${*}\007"
else
export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007"'
fi
}
title
It will let you toggle the name of a tab between a custom name and a default of your CWD.
title -> your tab title will be ~/YOUR_CWD/
title hey there -> your tab title will be hey there
- 181
- 1
- 2
I really like taylorstine's answer, but it breaks iTerm2's shell integration which relies on the PROMPT_COMMAND variable. You can modify Taylor's code to correct this by adding the __bp_precmd_invoke_cmd back into the PROMPT_COMMAND any time you tinker with it:
# iTerm2 shell integration
test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"
# iTerm2 tab titles
function title {
if [ "$1" ]
then
export PROMPT_COMMAND='__bp_precmd_invoke_cmd'
echo -ne "\033]0;${*}\007"
else
export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/\~}\007";__bp_precmd_invoke_cmd'
fi
}
title
- 1,185
I was looking for solution which works on vanilla iTerm2. One quite nicely working which I've found is to add keyboard shortcut which will execute this option (available either by double clicking tab or by choosing from menu Window → Edit TabTitle)
To do so:
- open
Preferences- Cmd+, or menuiTerm2 → Preferences - go to
Keyssubmenu and click+at the bottom - record your preferred key stroke (like
Super+Ctrl+Shift+e) and choose "Action"Select Menu Item - choose
Edit Tab Titlefrom list of available positions - voila!
- 671
I like Michael's answer.
But what if .iterm2_shell_integration.bash does not exist?
Here's my take:
# iTerm2 shell integration
test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"
# iTerm2 tab titles
function title {
if [ "$1" ] ; then
test -e "${HOME}/.iterm2_shell_integration.bash" \
&& export PROMPT_COMMAND='iterm2_preexec_invoke_cmd' \
|| unset PROMPT_COMMAND
echo -ne "\033]0;${*}\007"
else
test -e "${HOME}/.iterm2_shell_integration.bash" \
&& export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007";iterm2_preexec_invoke_cmd' \
|| export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007"'
fi
}
title
- 5,213
- 151
I think Automatic Profile Switching and Badges are exactly designed for what you need:
Automatic Profile Switching iTerm2 can use information it knows about your current path, host name, and user name to change profiles. For example, your window's background color or the terminal's character encoding could change when connecting to different hosts.
Badges You can put a badge in the top right of your terminal showing information about the current session. It can show your username, hostname, or even custom data like the current git branch.
so the result may like this:
- 131
Preferences -> Profiles -> Terminal
uncheck Terminal may set Tab/Window title
Max Cantor's comment worked for me.
- 370
I would like to extend B Seven's answer a little for absolute clarity.
Since most of us would like to know how can one set a title of a tab even when they are not in local shell, instead of in remote shell (e.g over ssh).
Step 1. Preferences -> Profiles -> Terminal
uncheck Terminal may set Tab/Window title
Step 2. For each tabs, double click on the tab -> Session Title
Now, whatever you'd set in the session title, it would stay as is.
- 131
I created a script to set dirname and a custom color to an active iterm2 tab. https://gist.github.com/bastoker/95d2f1d7c1354cb6b888363103a90645
- 111
- 3
If you're using multiple panes(tmux) and you want to rename all of them (the tab title will still change if you're active in a different pane), you can press Option + Command + i to activate multi-pane input on all panes on your current tab and then press Command + i to rename all panes to the name you want. That way, no matter which pane is active, your tab will have the same name.
- 11
Other answers provide no consistent way to override the title. I.e. once you enter nvim the title will be lost. If you already know how your workspace will be, please take a look at itomate. It allows you to spawn several tabs and panes with persistent tab names. You can even run commands automatically to get things going quickly.
What you do is build an itomate.yaml with contents like this one:
version: "1.0"
profile: "Default"
tabs:
admin:
root: "$HOME/proj/test/server"
title: "admin"
panes:
- position: "1/1"
commands:
- "tabset --color #ff0000"
- "nvim"
- position: "1/2"
commands:
- "tabset --color #ff0000"
- "nvm use"
- "npm start"
customer:
root: "$HOME/proj/test/client1"
title: "customer"
panes:
- position: "1/1"
commands:
- "tabset --color #ffcc00"
- "nvim"
driver:
root: "$HOME/proj/test/client2"
title: "driver"
panes:
- position: "1/1"
commands:
- "tabset --color #00ffcc"
- "nvim"
and then you just need to run itomate to spawn your windows and tabs with the right names. itomate will set the titles in a way that not even vim or any other applications can change them.
You can see in the example, I also use tabset by Jason Sundram to modify the color of the tab. I want to advice against using tabset to set the name of the tab itself. It's rendered overlay make switching tabs slower and the set titles also don't persist when using other applications in your session.
- 933
- 2
- 14
- 24
Yuk, all those aliases and functions. Easier solution (if you are root), paste this into a terminal. This will create a 1 line bash script and put it in the path.
You can then change the title at any time using:
title "New title"
TARGET=/usr/local/bin/title
sudo tee "$TARGET" <<'EOF'
#!/usr/bin/env bash
echo -ne "\033]0;$*\007"
EOF
sudo chmod 755 "$TARGET"
Or just make a file call title somewhere in your path, or global path, and paste the two lines between EOF.
- 549
- 6
- 9



