Bash provides an environment variable called PROMPT_COMMAND. The contents of this variable are executed as a regular Bash command just before Bash displays a prompt[0]. You can use the output of regular commands in PROMPT_COMMAND. Here we use echo to construct the command to set the window title.
export PROMPT_COMMAND='echo -ne "\033]0;${PWD##*/}\007"'
The key sequence here is:
ESC]0;stringBEL
-- Set icon name and window title to $string
Breaking it down:
\033
- octal for ESC (escape)
\007
- octal for BEL (bell)
$PWD
- outputs current directory
${var##Pattern}
- Remove from $var the longest part of $Pattern that matches the front end of $var[1].
echo -n
- Do not output the trailing newline.
echo -e
- Enable interpretation of backslash-escaped characters
[0] http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x264.html
[1] http://tldp.org/LDP/abs/html/parameter-substitution.html