2022-04-03 04:35:11 +02:00
|
|
|
#!/usr/bin/env zsh
|
|
|
|
# Exit with the error code of the last command and an optional error message in
|
|
|
|
# bold pink. The error code is overridden by the first argument, if it is a
|
2022-04-03 05:08:51 +02:00
|
|
|
# number. Will return instead of exit when the shell is interactive.
|
|
|
|
# Put this in ${fpath} and load it with `autoload -U die`.
|
2022-04-03 04:35:11 +02:00
|
|
|
|
2022-04-03 07:38:33 +02:00
|
|
|
local errorcode=${?}
|
|
|
|
|
2022-04-03 05:47:50 +02:00
|
|
|
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
|
|
|
|
|
2022-04-03 04:35:11 +02:00
|
|
|
if [[ -v 1 && ${1} =~ '^[0-9]+$' ]]; then
|
|
|
|
errorcode=${1}
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -v 1 ]]; then
|
2022-04-09 22:00:57 +02:00
|
|
|
local colour="201"
|
|
|
|
[[ -v zsh_theme_colours ]] && colour=${zsh_theme_colours[highlight]}
|
|
|
|
print -Pnu2 "%B%F{${colour}}"
|
2022-04-03 04:35:11 +02:00
|
|
|
print -u2 "${@}"
|
|
|
|
print -Pnu2 "%f%b"
|
|
|
|
fi
|
|
|
|
|
2022-04-03 05:08:51 +02:00
|
|
|
[[ -o INTERACTIVE ]] && return ${errorcode}
|
2022-04-03 04:35:11 +02:00
|
|
|
exit ${errorcode}
|