-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathtoggle_logging.sh
More file actions
executable file
·64 lines (54 loc) · 1.5 KB
/
toggle_logging.sh
File metadata and controls
executable file
·64 lines (54 loc) · 1.5 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
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/variables.sh"
source "$CURRENT_DIR/shared.sh"
get_filename() {
local logging_path="$(get_tmux_option "$logging_path_option" "$default_logging_path")"
local logging_filename="$(get_tmux_option "$logging_filename_option" "$default_logging_filename")"
echo "${logging_path}/${logging_filename}"
}
start_pipe_pane() {
local filename="$(get_filename)"
"$CURRENT_DIR/start_logging.sh" "$filename"
display_message "Started logging to $filename"
}
stop_pipe_pane() {
tmux pipe-pane
display_message "Ended logging to $(get_filename)"
}
# returns a string unique to current pane
pane_unique_id() {
tmux display-message -p "#{session_name}_#{window_id}_#{pane_id}"
}
# saving 'logging' 'not logging' status in a variable unique to pane
set_logging_variable() {
local value="$1"
local pane_unique_id="$(pane_unique_id)"
tmux set-option -gq "@${pane_unique_id}" "$value"
}
# this function checks if logging is happening for the current pane
is_logging() {
local pane_unique_id="$(pane_unique_id)"
local current_pane_logging="$(get_tmux_option "@${pane_unique_id}" "not logging")"
if [ "$current_pane_logging" == "logging" ]; then
return 0
else
return 1
fi
}
# starts/stop logging
toggle_pipe_pane() {
if is_logging; then
set_logging_variable "not logging"
stop_pipe_pane
else
set_logging_variable "logging"
start_pipe_pane
fi
}
main() {
if supported_tmux_version_ok; then
toggle_pipe_pane
fi
}
main