Skip to content

Commit ac30255

Browse files
author
Bruno Sutic
committed
Refactor 'start_logging' script
1 parent d0d7348 commit ac30255

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

scripts/start_logging.sh

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

3-
# path to log file
4-
file=$1
3+
# path to log file - global variable
4+
FILE="$1"
55

66
ansifilter_installed() {
77
type ansifilter >/dev/null 2>&1 || return 1
@@ -12,38 +12,33 @@ system_osx() {
1212
}
1313

1414
pipe_pane_ansifilter() {
15-
local file=$1
16-
tmux pipe-pane "exec cat - | ansifilter >> $file"
15+
tmux pipe-pane "exec cat - | ansifilter >> $FILE"
1716
}
1817

1918
pipe_pane_sed_osx() {
20-
local file=$1
2119
# Warning, very complex regex ahead.
2220
# Some characters below might not be visible from github web view.
2321
local ansi_codes_osx="(\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]||]0;[^]+|[[:space:]]+$)"
24-
tmux pipe-pane "exec cat - | sed -E \"s/$ansi_codes_osx//g\" >> $file"
22+
tmux pipe-pane "exec cat - | sed -E \"s/$ansi_codes_osx//g\" >> $FILE"
2523
}
2624

2725
pipe_pane_sed() {
28-
local file=$1
2926
local ansi_codes="(\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]|)"
30-
tmux pipe-pane "exec cat - | sed -r 's/$ansi_codes//g' >> $file"
27+
tmux pipe-pane "exec cat - | sed -r 's/$ansi_codes//g' >> $FILE"
3128
}
3229

3330
start_pipe_pane() {
34-
local file=$1
3531
if ansifilter_installed; then
36-
pipe_pane_ansifilter "$file"
32+
pipe_pane_ansifilter
3733
elif system_osx; then
3834
# OSX uses sed '-E' flag and a slightly different regex
39-
pipe_pane_sed_osx "$file"
35+
pipe_pane_sed_osx
4036
else
41-
pipe_pane_sed "$file"
37+
pipe_pane_sed
4238
fi
4339
}
4440

4541
main() {
46-
local file=$1
47-
start_pipe_pane "$file"
42+
start_pipe_pane
4843
}
49-
main "$file"
44+
main

0 commit comments

Comments
 (0)