-
-
Notifications
You must be signed in to change notification settings - Fork 129
/
debug
executable file
·92 lines (74 loc) · 2.42 KB
/
debug
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
89
90
#!/usr/bin/env zsh
indent=" "
# Ref: https://gitlab.gnome.org/GNOME/gnome-shell/issues/1
function skip-crap {
local datep="[0-9][0-9]:[0-9][0-9]:[0-9][0-9]: "
local crap_start="^${datep}Object [^ ]+ \(.*\), has been already finalized. Impossible to \w* any property \w* it.*"
local crap_continue=(
"^${datep}== Stack trace for context.*"
"^${datep}#[0-9]+\s*0x.*"
)
local skip=0
local skipped=0
local begin_skip_date
# Could probably be done more elegantly with awk/sed ?
while IFS=$'\n' read -r line; do
if [[ $line =~ $crap_start ]]; then
# echo setting skip
skip=1
begin_skip=$line
((skipped += 1))
continue
fi
if [[ $skip == 1 ]]; then
if [[ ($line =~ $crap_continue[1]) ||
($line =~ $crap_continue[2]) ]]; then
((skipped += 1))
continue
else
# echo reset skip
echo -E "$begin_skip"
printf "${indent}... skipped \"already finalized\" crap ($skipped lines)\n"
skip=0
skipped=0
fi
fi
echo -E "$line"
done
}
# We use non-breaking space to encode newlines in multiline messages
function decode-multiline-message {
stdbuf -oL sed -e 's| |\n |g'
}
function gnome-shell-exe-path {
if systemctl --user status gnome-shell-x11.service > /dev/null; then
echo --user-unit=gnome-shell-x11.service
elif systemctl --user status gnome-shell-wayland.service > /dev/null; then
echo --user-unit=gnome-shell-wayland.service
elif uname -a | grep --silent "NixOS"; then
echo $(dirname =gnome-shell(:A))/.gnome-shell-wrapped
else
echo =gnome-shell
fi
}
function procees {
jq --unbuffered --raw-output '
{ts: .__REALTIME_TIMESTAMP, message: .MESSAGE}
| @sh "TS=\(.ts); MESSAGE=\(.message)\u0000"
' | while read -r -d $'\0' DATA; do
eval $DATA
TS=$((TS/1000000))
PP_TS=$(date -d @${TS} +'%T')
if [[ $MESSAGE == *$'\n'* ]]; then
echo $PP_TS:
echo -E $MESSAGE | sed 's/^/ /'
else
echo -E "$PP_TS: $MESSAGE"
fi
done
}
journalctl --follow --lines 400 -o json --output-fields MESSAGE \
$@ $(gnome-shell-exe-path) \
| procees \
| skip-crap \
| decode-multiline-message