mirror of
https://github.com/zoriya/cish.git
synced 2025-12-05 23:06:18 +00:00
40 lines
776 B
Bash
Executable File
40 lines
776 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
SCRIPT=$(realpath "$1")
|
|
cd -- "$(dirname -- "$SCRIPT")"
|
|
|
|
exec \
|
|
3>&1 \
|
|
2> >(sed "s/^/[ERR] /" >&3) \
|
|
> >(sed "s/^/[INF] /" >&3)
|
|
|
|
_CISH_STARTED=false
|
|
function _cish_on_command() {
|
|
_CISH_EXIT_CODE=$?
|
|
|
|
# we don't wanna handle subscripts or commands originating from the debug trap
|
|
if [[ "${BASH_SOURCE[1]}" != "$SCRIPT" ]]; then
|
|
return
|
|
fi
|
|
sync
|
|
if [[ "$_CISH_STARTED" == true ]]; then
|
|
echo "exit code: $_CISH_EXIT_CODE" >&3
|
|
fi
|
|
_CISH_STARTED=true
|
|
echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} $BASH_COMMAND" >&3
|
|
}
|
|
|
|
function _cish_on_error() {
|
|
_CISH_VALID_EXIT_CODE=$?
|
|
_cish_on_command
|
|
exit "$_CISH_VALID_EXIT_CODE"
|
|
}
|
|
|
|
shopt -s extdebug
|
|
trap _cish_on_command DEBUG
|
|
trap _cish_on_error ERR
|
|
|
|
# shellcheck source=/dev/null
|
|
source "$SCRIPT"
|