From: Ian Kelling Date: Sat, 1 Feb 2025 05:52:25 +0000 (-0500) Subject: fix debug-setx to work with other debug traps X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=0916c47be2926b268776048f7bb729a8dff4f474;p=distro-setup fix debug-setx to work with other debug traps --- diff --git a/brc b/brc index 9c54ab9..e4983b3 100644 --- a/brc +++ b/brc @@ -4018,7 +4018,7 @@ if [[ $- == *i* ]]; then fi # make the titlebar be the last command and the current directory. - auto-window-title () { + auto-window-title() { # These are some checks to help ensure we dont set the title at diff --git a/fsf-script-lib b/fsf-script-lib index 9876c10..631ccfa 100644 --- a/fsf-script-lib +++ b/fsf-script-lib @@ -118,12 +118,13 @@ err() { echo "$(date "+%F %T") ${FUNCNAME[1]}: $*" >&2; } # # 1: set debug_max_stack_depth to >= 1. Default = 0. # -# 2: Allow specific functions with setx-func (see its doc below). +# 2: Allow printing in specific functions with setx-func (see its doc below). # # There is a hard-coded list of commands to skip or maybe skip. You can # improve this. # debug-setx() { + local existing_debug_trap # Note on commands we skip printing: # - read ends up being what is shown for 'while read' loops. @@ -135,11 +136,15 @@ debug-setx() { debug_skip=false debug_force_print=false - trap _debug-setx-func DEBUG + existing_debug_trap=$(trap -p DEBUG 2>&1) + if [[ $existing_debug_trap && $existing_debug_trap != *_debug-setx-func ]]; then + trap "$existing_debug_trap; _debug-setx-func" DEBUG + else + trap _debug-setx-func DEBUG + fi } # internal function called via debug-setx trap. _debug-setx-func() { - trap DEBUG local doprint=false random_delimiter func cmd col debug_cmd if [[ $debug_max_stack_depth ]]; then @@ -150,13 +155,11 @@ _debug-setx-func() { fi if [[ $BASH_SUBSHELL != [01] ]]; then - trap _debug-setx-func DEBUG return 0 fi if $debug_skip; then debug_skip=false - trap _debug-setx-func DEBUG return 0 fi @@ -240,7 +243,6 @@ _debug-setx-func() { done debug_prompt=false fi - trap _debug-setx-func DEBUG } # usage: ux [COMMAND...]