I kind of get sick of my work computer dying, and then I lose some history because I forgot to exit my terminal sessions. I’ve always used the histappend feature, but this prompt command thing is great. 😀 Thank you Stack Exchange. The other benefit of this is that each terminal immediately receives the new history next time you press enter.
shopt -s histappend # append to history, don't overwrite it export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"