Skip to content

Commit 5085290

Browse files
author
Phil Hindman
committed
Save logging filename in pane-specific variable
When logging is started, save the name of the log file in the variable. When logging is stopped, use the variable to display the name of the file, then clear the variable. Use whether the variable is empty or not to determine if logging has been started.
1 parent 6455c71 commit 5085290

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

scripts/toggle_logging.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ start_pipe_pane() {
1010
local file=$(expand_tmux_format_path "${logging_full_filename}")
1111
"$CURRENT_DIR/start_logging.sh" "${file}"
1212
display_message "Started logging to ${file}"
13+
set_logging_variable "${file}"
1314
}
1415

1516
stop_pipe_pane() {
1617
tmux pipe-pane
17-
display_message "Ended logging to $logging_full_filename"
18+
display_message "Ended logging to $(get_logging_variable)"
19+
set_logging_variable ""
1820
}
1921

2022
# returns a string unique to current pane
2123
pane_unique_id() {
2224
tmux display-message -p "#{session_name}_#{window_index}_#{pane_index}"
2325
}
2426

25-
# saving 'logging' 'not logging' status in a variable unique to pane
27+
# saving value in a variable unique to pane
2628
set_logging_variable() {
2729
local value="$1"
2830
local pane_unique_id="$(pane_unique_id)"
@@ -31,13 +33,13 @@ set_logging_variable() {
3133

3234
get_logging_variable() {
3335
local pane_unique_id="$(pane_unique_id)"
34-
local current_pane_logging="$(get_tmux_option "@${pane_unique_id}" "not logging")"
36+
local current_pane_logging="$(get_tmux_option "@${pane_unique_id}")"
3537
echo $current_pane_logging
3638
}
3739

3840
# this function checks if logging is happening for the current pane
3941
is_logging() {
40-
if [ "$(get_logging_variable)" == "logging" ]; then
42+
if [ -n "$(get_logging_variable)" ]; then
4143
return 0
4244
else
4345
return 1
@@ -47,10 +49,8 @@ is_logging() {
4749
# starts/stop logging
4850
toggle_pipe_pane() {
4951
if is_logging; then
50-
set_logging_variable "not logging"
5152
stop_pipe_pane
5253
else
53-
set_logging_variable "logging"
5454
start_pipe_pane
5555
fi
5656
}

0 commit comments

Comments
 (0)