I learned about this in college to make the title of xterms dynamic and found that the same method works with Terminal.app. I've created some aliases that allow me to have the title of the window reflect the machine that I'm on and current working directory of the shell, or of what file I'm editing. If you'd like a title on your terminal window that changes based on what you're doing, read the rest of this article...
The title in my example only contains the name of the current directory and the parent directory (so if I was in my Documents directory on my laptop called greyhound, the title would look like:
greyhound: cft/DocumentsI also use the same technique for my prompt so that when in real deep directories, my prompt does not go totally across the window. I have included a sample alias called setPrompt2 that does this. When editing a file with vi, it would look like:
greyhound: vi file_namePlease note that if you suspend a vi session, it will not change the title back, that will only happen when vi exits (or is killed). Changing directories with cd will always update the title bar.
alias settitle 'set t=$cwd:h;echo -n "^[]2;${HOST}: "!*"^G"'
alias setPrompt 'settitle $t:t/$cwd:t'
alias cd 'cd !*;setPrompt'
alias vi 'settitle "vi !*"; vi !*; settitle $t:t/$cwd:t'
setPrompt
alias setPrompt2 'set t=$cwd:h;set prompt="${USER}@$HOST $t:t/$cwd:t !> ";settitle $t:t/$cwd:t'Please note that in the alias settitle there are two control characters, ^[ and ^G. Control characters do not copy and paste correctly so you will need to edit them by hand. To enter them you need to use vi and type control-v then then the control character that you want (control-[ and control-G). Emacs should work too, but I do not know how to enter them in emacs.
source settitleThis assumes the aliases are in a file called settitle. To make it automatic whenever you start a new shell, put them in a file called .tcshrc in your home directory.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20010522025350220