fix debug-setx to work with other debug traps
authorIan Kelling <ian@iankelling.org>
Sat, 1 Feb 2025 05:52:25 +0000 (00:52 -0500)
committerIan Kelling <ian@iankelling.org>
Sat, 1 Feb 2025 05:52:25 +0000 (00:52 -0500)
brc
fsf-script-lib

diff --git a/brc b/brc
index 9c54ab924e473b62151cde645e92540f1f91d96e..e4983b3df98a42c6443da6939879ba4583f300c1 100644 (file)
--- 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
index 9876c104863ccf52f7367515f917dc1290419d82..631ccfaa6a326bc1d1a9db52e2ac6cd0cef051b9 100644 (file)
@@ -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...]