Set zsh title changing

2009 January 6
tags:
by Philippe Delodder

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 →
  1. January 28, 2009

    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.

  2. Bonini permalink
    June 19, 2009

    Thanks for the great post. I had added a link to your site to share this information around.

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS

Bad Behavior has blocked 367 access attempts in the last 7 days.