Change iTerm2 window and tab titles in zsh
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
.
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 Oh My Zsh, then you may need to edit your settings. Your settings are typically in the file ~/.zshrc
. You want to add or edit your settings to make sure this line exists:
DISABLE_AUTO_TITLE="true"
One of the amenities of using iTerm is the possibility of setting window title & tab 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.