Often a user will start a long-lived foreground job such as top, an editor, an email client, etc, and wishes the name of the job to be shown in the title. This is a more thorny problem and is only achieved easily in zsh.
top
zsh
zsh provides an ideal builtin function for this purpose:
preexec() a function which is just before a command is executed $*,$1,... arguments passed to preexec()
case $TERM in xterm*) preexec () { print -Pn "\e]0;$*\a" } ;; esac
preexec()
This is not easy in other shells which lack an equivalent of the preexec() function. If anyone has examples please email them to the author.