Catch Trap Interrupt

foo1(){
  echo hi-fail
  return 1
}

foo() {
  eai echo hi1
  eai echo hi2
  eai foo1
  eai echo hi3
}
export -f foo

cleanup() {
  echo "Caught signal."
  echo.green "Cleaning up..."

  # By default with we seem to exit the script with non-zero status.
  # However, let's be explicit with that code you want to exit in case 
  # of a clean up.
  # 
  # exit 0
  # exit 1
}

main() {
   trap cleanup SIGINT

   foo

   echo.yellow "Past foo (should not see this)"
}

main "${@}" && {
  echo.yellow "Exiting with success"
} || {
  echo.yellow "Exiting with failure"
}
mac> ${SCRATCH_SHELL} && echo ZERO_EXIT || echo NON_ZERO_EXIT
> echo hi1 (ROOT_PID:26333, BASHPID:26333)
hi1
Successfully completed: [echo hi1] (ROOT_PID:26333, BASHPID:26333)
> echo hi2 (ROOT_PID:26333, BASHPID:26333)
hi2
Successfully completed: [echo hi2] (ROOT_PID:26333, BASHPID:26333)
> foo1 (ROOT_PID:26333, BASHPID:26333)
hi-fail
Failed to execute: [foo1] (ROOT_PID:26333, BASHPID:26333)
Interrupting: Failed to execute [foo1]
FunctionChain: (main:34-->main:29-->foo:9-->eai:0-->execute_announce_or_interrupt:0-->throw:0-->interrupt)
PWD: /usr/local/workplace/thorg-root
PID    : 26333
BASHPID: 26333
Caught signal.
Cleaning up...
NON_ZERO_EXIT