...
This commit is contained in:
32
examples/tmuxrunnerexamples/functions/base.sh
Normal file
32
examples/tmuxrunnerexamples/functions/base.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
# Common error handling setup
|
||||
# set -euo pipefail
|
||||
|
||||
SCRIPT="${BASH_SOURCE[-1]}" # last sourced = the actual script file
|
||||
ERROR_FILE="$SCRIPT.error"
|
||||
DONE_FILE="$SCRIPT.done"
|
||||
|
||||
# Reset markers
|
||||
rm -f "$ERROR_FILE" "$DONE_FILE"
|
||||
|
||||
error_handler() {
|
||||
local exit_code=$?
|
||||
local line_no=$1
|
||||
local cmd="$2"
|
||||
{
|
||||
echo "EXIT_CODE=$exit_code"
|
||||
echo "LINE=$line_no"
|
||||
echo "COMMAND=$cmd"
|
||||
} > "$ERROR_FILE"
|
||||
|
||||
# If we are inside a sourced script, don't kill the shell
|
||||
if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
|
||||
return $exit_code
|
||||
else
|
||||
exit $exit_code
|
||||
fi
|
||||
}
|
||||
trap 'error_handler ${LINENO} "$BASH_COMMAND"' ERR
|
||||
|
||||
mark_done() {
|
||||
touch "$DONE_FILE"
|
||||
}
|
Reference in New Issue
Block a user