Você quer capturar o SIGHUP;
De man 7 signal
:
SIGHUP 1 Term Hangup detected on controlling terminal or death of controlling process
Então, para capturar SIGHUP e EXIT:
trap 'export HISTFILE=/tmp/custom.hist' 1 EXIT
ou:
trap 'export HISTFILE=/tmp/custom.hist' SIGHUP EXIT