26 lines
713 B
Bash
Executable File
26 lines
713 B
Bash
Executable File
#!/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
|
|
# number. Will return instead of exit when the shell is interactive.
|
|
# Put this in ${fpath} and load it with `autoload -U die`.
|
|
|
|
local errorcode=${?}
|
|
|
|
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
|
|
|
|
if [[ -v 1 && ${1} =~ '^[0-9]+$' ]]; then
|
|
errorcode=${1}
|
|
shift
|
|
fi
|
|
|
|
if [[ -v 1 ]]; then
|
|
local colour="201"
|
|
[[ -v zsh_theme_colours ]] && colour=${zsh_theme_colours[highlight]}
|
|
print -Pnu2 "%B%F{${colour}}"
|
|
print -u2 "${@}"
|
|
print -Pnu2 "%f%b"
|
|
fi
|
|
|
|
[[ -o INTERACTIVE ]] && return ${errorcode}
|
|
exit ${errorcode}
|