-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathdebug.sh
88 lines (78 loc) · 2.57 KB
/
debug.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
# shellcheck disable=2129
gf_emit_log_and_reset() {
>&2 cat "$GF_LOG_LOCATION"
}
if [ -z "$GF_LOG_LOCATION" ]; then
if [ -d "$TMPDIR" ]; then
# NB: TMPDIR on macOS has a trailing slash
GF_LOG_LOCATION="${TMPDIR%/}/git-fuzzy-log"
else
GF_LOG_LOCATION="$HOME/.git-fuzzy-log"
fi
export GF_LOG_LOCATION
rm -f "$GF_LOG_LOCATION"
touch "$GF_LOG_LOCATION"
trap gf_emit_log_and_reset EXIT
fi
gf_log_warning() {
printf "[%s%sWRN%s]" "$YELLOW" "$BOLD" "$NORMAL" >> "$GF_LOG_LOCATION"
printf " %s" "$@" >> "$GF_LOG_LOCATION"
echo >> "$GF_LOG_LOCATION"
}
gf_log_error() {
printf "[%s%sERR%s]" "$RED" "$BOLD" "$NORMAL" >> "$GF_LOG_LOCATION"
printf " %s" "$@" >> "$GF_LOG_LOCATION"
echo >> "$GF_LOG_LOCATION"
}
gf_log_debug() {
if [ -n "$GF_DEBUG_MODE" ]; then
printf "[%s%sDBG%s]" "$GRAY" "$BOLD" "$NORMAL" >> "$GF_LOG_LOCATION"
printf " %s" "$@" >> "$GF_LOG_LOCATION"
echo >> "$GF_LOG_LOCATION"
fi
}
gf_log_command() {
if [ -n "$GF_COMMAND_DEBUG_MODE" ]; then
if [ "$#" -gt 0 ]; then
printf "[%s%sCMD%s]" "$GREEN" "$BOLD" "$NORMAL" >> "$GF_LOG_LOCATION"
printf '%s' "$GRAY" "$BOLD" ' $ ' "$NORMAL" "$CYAN" "$BOLD" "$(quote_params "$1")" "$NORMAL" >> "$GF_LOG_LOCATION"
shift
printf ' %s' "$GREEN" "$(quote_params "$@")" >> "$GF_LOG_LOCATION"
printf '%s' "$NORMAL" >> "$GF_LOG_LOCATION"
echo >> "$GF_LOG_LOCATION"
else
# shellcheck disable=2016
error_exit '`gf_log_command` requires an actual command'
fi
fi
}
gf_log_command_string() {
if [ -n "$GF_COMMAND_DEBUG_MODE" ]; then
if [ "$#" -gt 0 ]; then
printf "[%s%sCMD%s]" "$GREEN" "$BOLD" "$NORMAL" >> "$GF_LOG_LOCATION"
printf '%s%s%s%s' "$GRAY" "$BOLD" ' $ ' "$NORMAL" >> "$GF_LOG_LOCATION"
printf '%s%s%s' "$CYAN" "$1" "$NORMAL" >> "$GF_LOG_LOCATION"
echo >> "$GF_LOG_LOCATION"
else
# shellcheck disable=2016
error_exit '`gf_log_command_string` requires an actual command'
fi
fi
}
gf_log_internal() {
if [ -n "$GF_INTERNAL_COMMAND_DEBUG_MODE" ]; then
if [ "$#" -gt 0 ]; then
printf "[%s%sCMD%s] (internal)" "$GRAY" "$BOLD" "$NORMAL" >> "$GF_LOG_LOCATION"
printf '%s' "$GRAY" "$BOLD" ' $ ' "$CYAN" "$BOLD" "$1" "$NORMAL" >> "$GF_LOG_LOCATION"
shift
printf '%s' "$GREEN" >> "$GF_LOG_LOCATION"
printf '%s' "$(quote_params "$@")" >> "$GF_LOG_LOCATION"
printf '%s' "$NORMAL" >> "$GF_LOG_LOCATION"
echo >> "$GF_LOG_LOCATION"
else
# shellcheck disable=2016
error_exit '`gf_log_internal` requires an actual command'
fi
fi
}