(Inspired by this SU answer)
You can combine a couple bash tricks:
- If you trap a DEBUG signal, the handler is called before each command is executed
- The variable
$BASH_COMMAND holds the currently executing command
So, trap DEBUG and have the handler set the title to $BASH_COMMAND:
trap 'echo -ne "\033]0;$BASH_COMMAND\007"' DEBUG
This will keep the title changed until something else changes it, but as long as your $PS1 stays the same it won't be a problem -- you start a command, the DEBUG handler changes the titlebar, and when the command finishes bash draws a new prompt and resets your titlebar again.
A useful tip found here (also where that SU answer came from) is to include:
set -o functrace
This will make bash propagate the DEBUG trap to any subshells you start; otherwise the titlebar won't be changed in them