A bash PROMPT_COMMAND to cover all the cases i usually encounter, cobbled together from random sources + some magic of my own