photo
Jordan Sissel
geek

Thu, 07 Oct 2004

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:

HOST=`hostname`
HOST=${HOST%%.*}

preexec() {
	xterm_title $1
}

xterm_title() {
	case $TERM in
			(x|dt|a|E)term|screen|rxvt)
				echo -n "^[]0;$* @ $HOST^G"
			;;
	esac
}

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

Comments: 0 (view comments)
Tags:
Permalink: /geekery/127
posted at: 14:14

Search this site

Navigation

Metadata

Home About Resume My Code (SVN)

Articles

ARP Security Dynamic DNS with DHCP OpenLDAP+Kerberos+SASL PPP over SSH SSH Security: /bin/false Week of Unix Tools Work Efficiency

Projects

fex firefox tabsearch firefox urledit grok keynav liboverride newpsm (FreeBSD) nis2ldap pam_captcha poor man's backup Solaris audio utility xboxproxy xdotool xmlpresenter xpathtool misc scripts

Presentations

Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials

Tag Cloud

Calendar

< October 2004 >
SuMoTuWeThFrSa
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930
31      

Friends

BarCamp Kent Brewster Tantek Çelik John Resig Wesley Shields Tyler Shields

Technorati