#
# 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.
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
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
done
debug_prompt=false
fi
- trap _debug-setx-func DEBUG
}
# usage: ux [COMMAND...]