From 23dc333c57901619f9f8278d14cfcf0a6000e38a Mon Sep 17 00:00:00 2001 From: Phil Hindman Date: Thu, 16 May 2024 22:53:03 -0500 Subject: [PATCH] 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. --- scripts/toggle_logging.sh | 24 +++++++++--------------- scripts/variables.sh | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/scripts/toggle_logging.sh b/scripts/toggle_logging.sh index 415a0d9..e1474fa 100755 --- a/scripts/toggle_logging.sh +++ b/scripts/toggle_logging.sh @@ -10,34 +10,30 @@ start_pipe_pane() { local file=$(expand_tmux_format_path "${logging_full_filename}") "$CURRENT_DIR/start_logging.sh" "${file}" display_message "Started logging to ${file}" + set_logging_variable "${file}" } stop_pipe_pane() { tmux pipe-pane - display_message "Ended logging to $logging_full_filename" + display_message "Ended logging to $(get_logging_variable)" + unset_logging_variable } -# returns a string unique to current pane -pane_unique_id() { - tmux display-message -p "#{session_name}_#{window_index}_#{pane_index}" +set_logging_variable() { + tmux set-option -pq @logging-filename "$1" } -# 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" +unset_logging_variable() { + tmux set-option -pu @logging-filename } get_logging_variable() { - local pane_unique_id="$(pane_unique_id)" - local current_pane_logging="$(get_tmux_option "@${pane_unique_id}" "not logging")" - echo $current_pane_logging + tmux show-option -pqv @logging-filename } # this function checks if logging is happening for the current pane is_logging() { - if [ "$(get_logging_variable)" == "logging" ]; then + if [ -n "$(get_logging_variable)" ]; then return 0 else return 1 @@ -47,10 +43,8 @@ is_logging() { # 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 } diff --git a/scripts/variables.sh b/scripts/variables.sh index a27c24f..fef5f4e 100644 --- a/scripts/variables.sh +++ b/scripts/variables.sh @@ -27,7 +27,7 @@ logging_path=$(tmux show-option -gqv "@logging-path") logging_path=${logging_path:-$default_logging_path} default_logging_filename="tmux-${filename_suffix}" -logging_filename=$(tmux show-option -gqv "@logging-filename") +logging_filename=$(tmux show-option -pqv "@logging-filename") logging_filename=${logging_filename:-$default_logging_filename} logging_full_filename="${logging_path}/${logging_filename}"