As I wrote in bash-shell-prompt, you can use $PS1 environment variable to make bash do valuable things. Now I find that the other variable $PROMPT_COMMAND can do a similar task.
Recently I began to use FreeBSD 4.11, cause bash is not FreeBSD’s default shell, it is not well configured in FreeBSD. For one thing, when I use putty to login to it, the window title is static, displaying whatever I set in putty’s preference. This is not the case with Red Hat Linux. I want to get the feature working on FreeBSD, after some searching I found $PROMPT_COMMAND is the point. Just copy its value from Linux box then FreeBSD works the same.
If you happen to use FreeBSD with bash, I recommend you set $PROMPT_COMMAND to the following value
echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"
just add the following to your .bashrc would do
export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'.