Skip to content

Commit 21fa15d

Browse files
committed
Automatically switch to Bash for --debug
1 parent 0e5578e commit 21fa15d

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

git-fmt-diff

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ cleanup () {
4949
done
5050
}
5151

52-
# When debugging, make sure 'sh' is a link to Bash executable
5352
debug () (
54-
[ "$3" != "--" ] && [ "$gf_debug" -eq 0 ] && return
55-
prg="$(basename "$0")"
56-
func="$1" && shift 1
57-
lineno="$1" && shift 1
58-
>&2 printf "[debug] %s @ %s:%d # %s\n" "$prg" "$func" "$lineno" "$*"
53+
[ "$1" != "--" ] && [ "$gf_debug" -eq 0 ] && return
54+
>&2 printf "[debug] %s" "$(basename "$0")"
55+
if [ -n "$BASH_VERSION" ]; then
56+
# shellcheck disable=SC3028,SC3054
57+
>&2 printf ":%-3d %30s" "${BASH_LINENO[0]}" "${FUNCNAME[1]}"'()'
58+
fi
59+
>&2 printf " | %s\n" "$*"
5960
)
60-
alias debug='debug "$FUNCNAME" "$LINENO"'
6161

6262
pat_list_to_case () {
6363
sed 's/\s*,\s*/|/g'
@@ -355,7 +355,7 @@ process_file () (
355355
a_name="$4"
356356
b_name="${5:-$a_name}"
357357

358-
debug "--- PROCESSING: $b_name ---"
358+
debug "# PROCESSING: $b_name #"
359359
debug "args = " "$@"
360360

361361
case "$(git_conf_get "$b_name" ignore)" in
@@ -496,6 +496,15 @@ EOU
496496
}
497497

498498
# parse options {{{2
499+
500+
case "$@" in
501+
--debug)
502+
if [ -z "$BASH_VERSION" ] && [ -x "$(command -v bash)" ]; then
503+
exec bash "$0" "$@"
504+
fi
505+
;;
506+
esac
507+
499508
while :; do
500509
case "$1" in
501510
-h)

0 commit comments

Comments
 (0)