From 59826c3997e7ff3d5ca59fe3ad252400f6132f71 Mon Sep 17 00:00:00 2001 From: pvincent Date: Thu, 23 Jul 2026 10:27:13 +0400 Subject: [PATCH] MIAOU_DEBUG --- bin/miaou-bash | 28 ++++++++++++++-------------- test/stub/scenario.bash | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/bin/miaou-bash b/bin/miaou-bash index 7c4dfa4..2705d62 100755 --- a/bin/miaou-bash +++ b/bin/miaou-bash @@ -3,8 +3,8 @@ # CONSTANTS MIAOU_BASH_ERROR=$(mktemp -t "$(basename "$0").XXXXXXXX" --tmpdir="/run/user/$(id -u)") -MIAOU_BASH_DEBUG=${MIAOU_BASH_DEBUG:-false} -readonly MIAOU_BASH_ERROR MIAOU_BASH_DEBUG +MIAOU_DEBUG=${MIAOU_DEBUG:-false} +readonly MIAOU_BASH_ERROR MIAOU_DEBUG # FUNCTIONS @@ -15,7 +15,7 @@ function is_true { # overridden function which permits backtracing of original `return` statement function false { >&2 echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} false" - debug "overridden false" + miaou_debug "overridden false" builtin false } @@ -24,7 +24,7 @@ function exit { code=${1:-0} # >&2 echo "${BASH_SOURCE[2]}: line ${BASH_LINENO[0]}: exit $@" >&2 echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]} exit $code" - debug "overridden exit $code" + miaou_debug "overridden exit $code" builtin exit "$code" } @@ -166,7 +166,7 @@ function on_exit { fi else # failure_type='UNDEFINED' - debug "last error=${last_error}" + miaou_debug "last error=${last_error}" failure_payload="${last_error}" regex="^ .*:[0-9]* .*\$" if [[ "$last_error" =~ $regex ]]; then @@ -196,8 +196,8 @@ function on_exit { builtin exit "$code" } -function debug { - is_true "${MIAOU_BASH_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true +function miaou_debug { + is_true "${MIAOU_DEBUG}" && >/dev/tty echo "*********** DEBUG: $*" || true } function ansi_block_continuation { @@ -248,22 +248,22 @@ function dump_failure { if [[ ${failure_type} == 'SUBSHELL SOURCE NOT FOUND' ]]; then : else - debug '---error---' + miaou_debug '---error---' if [[ $failure_type == 'SUBSHELL ERROR' ]]; then >&4 echo -e "${failure_payload}" else >&4 ansi_block_error "$failure_type" "$failure_payload" "$code" fi - debug '---end of error---' + miaou_debug '---end of error---' fi - debug '---stacktrace---' + miaou_debug '---stacktrace---' >&4 ansi_traces stack_sources stack_lines stack_functions # for i in "${failure_traces[@]}"; do # >&4 echo -e "$i" # done - debug '---end of stacktrace---' + miaou_debug '---end of stacktrace---' cleanup } @@ -272,13 +272,13 @@ function dump_stderr { mapfile -t tmp_error <"$MIAOU_BASH_ERROR" is_true "$last_trim" && unset 'tmp_error[-1]' && tmp_error=("${tmp_error[@]}") if [[ "${#tmp_error[@]}" -gt 0 ]]; then - debug '---stderr---' + miaou_debug '---stderr---' >&4 printf '\r' for i in "${tmp_error[@]}"; do >&4 echo -e "$i" done else - debug '---no stderr---' + miaou_debug '---no stderr---' fi } @@ -306,7 +306,7 @@ BASH_ARGV0="$1" && shift # to pretend script runs by itself # magic FD + delayed tee => /dev/fd/3 means delayed stderr, /dev/fd/4 remains original stderr exec 3> >(tee "$MIAOU_BASH_ERROR" >/dev/null) 4>/dev/stderr -debug '---stdout---' +miaou_debug '---stdout---' # shellcheck source=/dev/null source "$BASH_ARGV0" 2>&3 dump_success diff --git a/test/stub/scenario.bash b/test/stub/scenario.bash index 877182f..91e8bc3 100755 --- a/test/stub/scenario.bash +++ b/test/stub/scenario.bash @@ -13,8 +13,8 @@ function do_subshell_false { } function do_subshell_term { - echo "found1=$(command_not_found)" echo "found2=$(grep nope nope)" + echo "found1=$(command_not_found)" echo SHOULD NOT SHOW UP! }