Automatic Terminal Emulator Tab Naming

…with ZSH.

I’ve only tested this in iTerm and Konsole, but feel free to try it in another terminal emulator.

Put the following in your ~/.zshrc:

title()   { print -Pn "\e]0;$*\a" }
precmd()  { title "zsh: $(basename $PWD)" }
preexec() { title $1 }

This will give you tab names like “zsh: /”, “top” and so on. It is nice.


You might want to put the code above in some kind of if statement in order to deal with odd terminals (e.g. screen).