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: