Set zsh title changing
2009 January 6
Changing the title each time you type a command in zsh easy with precmd () and preexec (). You can find more about those commands here.
The precmd() is executed just before the prompt is drawn. The preexec() function is executed just before the command is executed. So with preexec () it could be possible to set in the the executing command.
Here is my version of zsh to set a title it’s almost identical to the one found on the site. But here I make use of preexec (), here is my version:
case $TERM in
sun-cmd)
precmd () { print -Pn "\e]l%~\e\\" }
preexec () { print -Pn "\e]l%~\e\\" }
;;
*xterm*|rxvt|(dt|k|E)term)
precmd () { print -Pn "\e]2;%n@%m:%~\a" }
preexec () { print -Pn "\e]2;%n@%m:%~\a" }
;;
esac
Just put the code in you .zshrc file and reload the config file with this:
source $HOME/.zshrc
3 Responses
leave one →
Great! Thank you!
I always wanted to write in my blog something like that. Can I take part of your post to my blog?
Of course, I will add backlink?
Sincerely, Timur I.
Yea sure, you can do that preferably add a blacklink
Thanks for the great post. I had added a link to your site to share this information around.