-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathstart_logging.sh
More file actions
executable file
·57 lines (46 loc) · 1.26 KB
/
start_logging.sh
File metadata and controls
executable file
·57 lines (46 loc) · 1.26 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
#!/usr/bin/env bash
# path to log file - global variable
FILE="$1"
# If called directly, read context and enable logging
if [ ! "${FILE}" ] ; then
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/variables.sh"
source "$CURRENT_DIR/shared.sh"
file=$(expand_tmux_format_path "${logging_full_filename}")
display_message "Started logging to ${logging_full_filename}"
fi
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"
}
start_pipe_pane() {
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
}
main() {
start_pipe_pane
}
main