-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathstart_logging.sh
More file actions
executable file
·67 lines (58 loc) · 1.28 KB
/
start_logging.sh
File metadata and controls
executable file
·67 lines (58 loc) · 1.28 KB
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
#!/usr/bin/env bash
# path to log file - global variable
FILE="$1"
# LOG FILTER
LOGGING_FILTER="$2"
ansifilter_installed() {
type ansifilter >/dev/null 2>&1 || return 1
}
system_osx() {
[ $(uname) == "Darwin" ]
}
pipe_pane_ansifilter() {
tmux pipe-pane "exec cat - | ansifilter >> $FILE"
}
pipe_pane_sed_osx() {
# Warning, very complex regex ahead.
# Some characters below might not be visible from github web view.
local ansi_codes_osx="(\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]||]0;[^]+|[[:space:]]+$)"
tmux pipe-pane "exec cat - | sed -E \"s/$ansi_codes_osx//g\" >> $FILE"
}
pipe_pane_sed() {
local ansi_codes="(\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]|)"
tmux pipe-pane "exec cat - | sed -r 's/$ansi_codes//g' >> $FILE"
}
pipe_pane_no_filter() {
tmux pipe-pane "exec cat >> $FILE"
}
start_pipe_pane() {
case "$LOGGING_FILTER" in
auto)
if ansifilter_installed; then
pipe_pane_ansifilter
elif system_osx; then
# OSX uses sed '-E' flag and a slightly different regex
pipe_pane_sed_osx
else
pipe_pane_sed
fi
;;
ansifilter)
pipe_pane_ansifilter
;;
sed_osx)
pipe_pane_sed_osx
;;
sed)
pipe_pane_sed
;;
*)
pipe_pane_no_filter
esac
}
main() {
start_pipe_pane
}
main