Search this site





zsh's preexec() and tcsh's postcmd

These are definately two of the most useful things I've ever run across in shelllyland. What they do is execute a function or alias (zsh or tcsh, respectively) just after you type something in at the command prompt.

This wonderful feature lets you change the xterm title just before execution of a potentially "long" process. This is most helpful for glancing at xterm titles and figuring out what is going on in the terminal. I don't have this setup for tcsh, however it is quite simple and is mentioned in tcsh's manpage. Search for 'alias postcmd'

Here is my zsh setup particular to this topic:


preexec() {
	xterm_title $1

xterm_title() {
	case $TERM in
				echo -n "^[]0;$* @ $HOST^G"

Now every time you execute a command (vim Foo.html, for instance), the xterm title will be updated with whatever command @ hostname.