Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
    
possible duplicate of Change iTerm2 window and tab titles in zsh – Daniel Beck May 2 '12 at 19:11
    
Not entirely duplicate. So how to add the currently running app as a part of tab title? I.e. which tab is running emacs, mysql, etc.? – qazwsx May 2 '12 at 19:16
    
I.e. all my tabs have same host and user. So using those won't differentiate my tabs. – qazwsx May 2 '12 at 19:27
    
You mean you want Show current job name from iTerm's preferences? Note that the linked topic isn't about username or host. – Daniel Beck May 2 '12 at 19:31
    
Right, I want to show some indication of what program is running or was run in each tabs. Also, the solution given in the other post doesn't work for Bash + iTerm2. – qazwsx May 2 '12 at 20:08
up vote 69 down vote accepted

Since you're using iterm2 on a mac, another option is you can just hit Cmd-I, type something, and hit Escape.

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

share|improve this answer
7  
This works for a second until I issue a return on the tab that I have renamed. – Stewie Jan 29 '14 at 15:39
1  
@Stewie In Preferences -> Profiles -> Terminal, uncheck "Allow terminal to report window title". – Max Cantor Apr 4 '14 at 13:19
3  
It is unchecked. It still renames the title. – Stewie Apr 6 '14 at 1:05
2  
@SteveBennett it's not the "theme" (actually the term is "profile") itself; the CMD+I command is "Edit Current Session..." (under the View menu), so it's just changing that tab's instance of the profile. Hitting Escape just closes the window, which is needed since that window doesn't have a "save" button on it. – MidnightLightning Aug 4 '15 at 13:39
1  
What if you have multiple panes open? Do you have to rename each one to fully name the tab itself? – theicfire Aug 10 '15 at 21:01

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.

share|improve this answer
    
I tried this, but it still doesn't work. I put this definition into bash_aliases, and have it loaded in .profile (if [ -f ${HOME}/.bash_aliases ]; then . ${HOME}/.bash_aliases fi) But then title dog didn't turn tab title into "dog" – qazwsx Jun 6 '13 at 21:06
1  
+1 - I added mine to /etc/profile just cause that's where my aliases are... don't forget to source the file after you're done. Note: this also works in terminal. – blak3r Dec 10 '13 at 19:52
1  
Very helpful. I wanted a pony; and I got one! – SoEzPz Oct 26 '15 at 16:55
    
I put mine in .bash_profile, restarted and it worked like a charm. – C Johnson Apr 14 at 20:33

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

share|improve this answer
    
Works! Just keep in mind that either .bashrc or .bash_profiles can be loaded and not both together. I already had a .bash_profiles file so I had to paste it into this file. Thanks. – therealmarv Jul 31 '13 at 11:13
1  
oh thanks! i've updated the answer to match this. i have "source ~/.bashrc" in my .bash_profile and forget that this is not common – PETER Aug 1 '13 at 11:59

Add this function to your ~/.bash_profile file and it should work.

function title ()
{
    TITLE=$*;
    export PROMPT_COMMAND='echo -ne "\033]0;$TITLE\007"'
}
share|improve this answer

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

share|improve this answer
    
Note that as-is, this will clobber iTerm shell integration. – Michael Mar 18 at 15:30

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 iterm2_preexec_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='iterm2_preexec_invoke_cmd'
        echo -ne "\033]0;${*}\007"
    else
        export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007";iterm2_preexec_invoke_cmd'
    fi
}
title
share|improve this answer

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
share|improve this answer

Yuk, all those aliases and functions. Easier solution (if you are root), paste this into a terminal:

TARGET=/usr/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.

share|improve this answer
4  
"Yuk with all those aliases." Enters answer no one can possible remember or type by hand. – Dan Jan 14 at 18:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.