iTerm2 – How to Change Window and Tab Titles in Zsh

command lineitermosx-snow-leopardzsh

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?

Best Answer

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

Related Question