Take the 2-minute tour ×
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
add comment

4 Answers

up vote 17 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
1  
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
2  
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
add comment

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 Terminal.app 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? –  Problemaniac May 2 '12 at 19:39
    
@duperuser That's right. –  Orangenhain May 3 '12 at 8:21
add comment

What works on Mac OSX and iTerm 2:

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

Also do iTerm → Preferences → Window & Tab Titles → uncheck all

share|improve this answer
add comment

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

http://apple.stackexchange.com/a/90737/49605

share|improve this answer
add comment

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.