Closed QwertyZW closed 5 years ago
Allow bash3boilerplate to provide the ultimate debugging experience.
If you want add timestamps and some colour to that:
set_debug_prompt() {
# ------------------------------------------------------------------
# | PS4 - Debug prompt string (when using `set -x`) |
# ------------------------------------------------------------------
#
# When debugging a shell script via `set -x` this tricked-out prompt is used.
# \011 - tab
# The first character (+) is used and repeated for stack depth.
# Then, we log the current time, filename and line number,
# followed by function name, followed by actual source line.
# [!] Don't change to double quotes
export PS4='+\011\e[1;30m\t \e[1;34m${BASH_SOURCE}\e[0m:\e[1;36m${LINENO}\e[0m \011 ${FUNCNAME[0]:+\e[0;35m${FUNCNAME[0]}\e[1;30m()\e[0m:\011 }'
# if debug, but not colour, back to this one:
# export PS4='+\011\t ${BASH_SOURCE}:${LINENO} \011 ${FUNCNAME[0]:+${FUNCNAME[0]}():\011 }'
}
main() {
set_debug_prompt
}
main
# Cleanup.
unset -f set_debug_prompt
unset -f main
Hey that's pretty cool! Sorry for not noticing earlier! Merging this. I'd be open to accepting a PR for colors, too!
Hey that's pretty cool! I'd be open to accepting a PR for colors, too!
Working on it. Testing to see if I can (and should) include colour prompt in the error backtracing TRAP.
@kvz FYI something is failing on CI
Will take this to #105 for followup and closure.
Allow bash3boilerplate to provide the ultimate debugging experience. PS4 provided by http://wiki.bash-hackers.org/scripting/debuggingtips