Skip to content

Commit 23dc333

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 23dc333

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

scripts/toggle_logging.sh

+9-15
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,30 @@ 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+
unset_logging_variable
1820
}
1921

20-
# returns a string unique to current pane
21-
pane_unique_id() {
22-
tmux display-message -p "#{session_name}_#{window_index}_#{pane_index}"
22+
set_logging_variable() {
23+
tmux set-option -pq @logging-filename "$1"
2324
}
2425

25-
# saving 'logging' 'not logging' status in a variable unique to pane
26-
set_logging_variable() {
27-
local value="$1"
28-
local pane_unique_id="$(pane_unique_id)"
29-
tmux set-option -gq "@${pane_unique_id}" "$value"
26+
unset_logging_variable() {
27+
tmux set-option -pu @logging-filename
3028
}
3129

3230
get_logging_variable() {
33-
local pane_unique_id="$(pane_unique_id)"
34-
local current_pane_logging="$(get_tmux_option "@${pane_unique_id}" "not logging")"
35-
echo $current_pane_logging
31+
tmux show-option -pqv @logging-filename
3632
}
3733

3834
# this function checks if logging is happening for the current pane
3935
is_logging() {
40-
if [ "$(get_logging_variable)" == "logging" ]; then
36+
if [ -n "$(get_logging_variable)" ]; then
4137
return 0
4238
else
4339
return 1
@@ -47,10 +43,8 @@ is_logging() {
4743
# starts/stop logging
4844
toggle_pipe_pane() {
4945
if is_logging; then
50-
set_logging_variable "not logging"
5146
stop_pipe_pane
5247
else
53-
set_logging_variable "logging"
5448
start_pipe_pane
5549
fi
5650
}

scripts/variables.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ logging_path=$(tmux show-option -gqv "@logging-path")
2727
logging_path=${logging_path:-$default_logging_path}
2828

2929
default_logging_filename="tmux-${filename_suffix}"
30-
logging_filename=$(tmux show-option -gqv "@logging-filename")
30+
logging_filename=$(tmux show-option -pqv "@logging-filename")
3131
logging_filename=${logging_filename:-$default_logging_filename}
3232

3333
logging_full_filename="${logging_path}/${logging_filename}"

0 commit comments

Comments
 (0)