Add this to you Bash profile file:
nohist() { history -d $HISTCMD; }; trap nohist ERR
EDIT: this is better as the error line can be retrieved easily:
ce() { eval "$BASH_COMMAND; e='$BASH_COMMAND'"; false; }
if [[ $- == *i* ]]; then trap ce ERR; fi # capture error command
alias e='$e' # type e and then expand with ctrl-alt-e
Also, this will capture every output for reuse (but it has an issue with echo and hist
save_output() {
exec 1>&3
{ [ -f /tmp/current ] && mv /tmp/current /tmp/last; }
exec > >(tee /tmp/current)
}
exec 3>&1
trap save_output DEBUG
https://stackoverflow.com/a/48398357/4240654