Article Image

For zsh, I decided I wanted to simply add a line to my zshrc file to set the window title for iTerm2 to $(hostname) of the box I was currently logged in to:

echo -ne "\e]1;${(hostname)}\a"

Yes, its that easy:)

Looking a little further into the superuser question. it appears theres another way that works for both bash and zsh and, by the author's note:

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.

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

I think thats probably one of the best comments I've seen on superuser ;P

Blog Logo

Mario Loria




Because gets old after a while.

Back to Overview