If you want your iTerm2 terminal window display the current Git branch
(when the current directory is inside a Git repository of course) add the following to
your .zshrc
:
set_terminal_title() {
git_branch=`git branch 2> /dev/null |\
sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'`
echo -ne "\e]1;$git_branch\a"
}
export PROMPT_COMMAND="$PROMPT_COMMAND; set_terminal_title"
precmd() { set_terminal_title }
Also, make sure your iTerm2 configuration (Prefences > Profiles > General) has the following settings: