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

I want to label the window tabs of terminal sessions. I'm using the zshell in iterm2 on OSX. Is it possible to change the label of a window tab dynamically in the terminal?

share|improve this question

5 Answers 5

up vote 28 down vote accepted

You can enter the following in zsh to set the window title of iTerm2:

echo -ne "\e]1;this is the title\a"

If you want to automate that to insert e.g. the current time or working directory, edit your zsh configuration files to set the title in the precmd() function to e.g. $PWD.

echo -ne "\e]1;$PWD\a"

You can read about the precmd function in man zshmisc in the section SPECIAL FUNCTIONS.

enter image description here

share|improve this answer
when I execute the command echo -ne "\e]1;this is the title\a" the tab title does not change. Is there a setting I have to change in iterm2? – bneil Jun 4 '11 at 5:45
Figured it out. I have to deselect all the options for window and tab titles in the iterm->preferences->appearance section. and in the .zshrc I have to uncomment/add export DISABLE_AUTO_TITLE="true" Thanks @Daniel Beck – bneil Jun 4 '11 at 5:49

One of the amenities of using iTerm is the possibility of setting window title & tab title separately: example of using tab & window title separately

# $1 = type; 0 - both, 1 - tab, 2 - title
# rest = text
setTerminalText () {
    # echo works in bash & zsh
    local mode=$1 ; shift
    echo -ne "\033]$mode;$@\007"
stt_both  () { setTerminalText 0 $@; }
stt_tab   () { setTerminalText 1 $@; }
stt_title () { setTerminalText 2 $@; }

This way you can immediately see what host you're connected to in what window, and the window title for each tab shows user & CWD.

share|improve this answer
I just noticed that the version in OS X Lion supports this as well. – Orangenhain Oct 8 '11 at 16:50
silly question: you add these code to .bashrc, right? – qazwsx May 2 '12 at 19:39
@duperuser That's right. – Orangenhain May 3 '12 at 8:21
Also appears that (in iTerm2 Build until you change the Window Title... it tracks the tab title, no matter what. I'm sure that's a setting. Once the Window title is changed (2) it no longer tracks tab title. – Mei Jul 23 '14 at 15:16
I modified the function above to include the line DISABLE_AUTO_TITLE="true" that fixed the issue and this way if I don't set the title, I still get the automatic title feature – user15681 Nov 16 at 14:42

What works for me:

echo -e "\033];this is the title\007"

If you use Mac OSX and iTerm, iTerm2::

  • iTerm → Preferences → Appearance → Window & Tab Titles → uncheck all

If you use zsh, then edit your settings, typically in ~/.zshrc, so you have this line:

share|improve this answer

Adding export PROMPT_COMMAND='echo -ne "\033]0;$PWD\007"' into ~/.bash_profile worked for me.

share|improve this answer
The question specifically says zsh, not bash. – blockloop Apr 30 at 14:09

A precmd does the trick. However, some oh-my-zsh themes mess around with the window title. Set PR_TITLEBAR to an empty string to fix it.

set-window-title() {
  # /Users/clessg/projects/dotfiles -> ~/p/dotfiles
  echo -ne "$window_title"

add-zsh-hook precmd set-window-title

I would also recommend playing around with the tab settings of iTerm2 in Preferences -> Appearance.

share|improve this answer

Your Answer


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.