Earlier answers didn't quite work for me. Not without some hiccups (not always refreshed or something). It may be due to the fact I had ZSH, without
oh-my-zsh. Fortunately I learned of
[[ -t 1 ]] || return
case $TERM in
sun-cmd) print -Pn "\e]l%~\e\\"
*xterm*|rxvt|(dt|k|E)term) print -Pn "\e]2;%~\a"
chpwd gets called every time directory is changed.
- first time you launch xterm (or others) this doesn't count as directory change, so put chpwd call directly in
As I do not use oh-my-zsh, I don't know if it works there, but unless they've changed and overwritten
chpwd (in which case you will be overwriting their overwrite :D), it should.