From c2854b2437c7d66af518d6f7921f209f972af628 Mon Sep 17 00:00:00 2001 From: Phil Hindman Date: Thu, 16 May 2024 22:18:07 -0500 Subject: [PATCH 1/6] Ensure that 'start logging' displays correct filename Previously the filename was calculated twice: first when opening the file, and then when displaying the message. There is a small chance that the time would change between those two events, causing the displayed filename to be incorrect. This change calculates the name once and then uses that name in both places. --- scripts/toggle_logging.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/toggle_logging.sh b/scripts/toggle_logging.sh index e240d8c..1672ba2 100755 --- a/scripts/toggle_logging.sh +++ b/scripts/toggle_logging.sh @@ -9,7 +9,7 @@ source "$CURRENT_DIR/shared.sh" start_pipe_pane() { local file=$(expand_tmux_format_path "${logging_full_filename}") "$CURRENT_DIR/start_logging.sh" "${file}" - display_message "Started logging to ${logging_full_filename}" + display_message "Started logging to ${file}" } stop_pipe_pane() { From 6455c71f562cfccf1bd4f0feda83a220d777568a Mon Sep 17 00:00:00 2001 From: Phil Hindman Date: Thu, 16 May 2024 22:45:24 -0500 Subject: [PATCH 2/6] Add get_logging_variable helper function --- scripts/toggle_logging.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/toggle_logging.sh b/scripts/toggle_logging.sh index 1672ba2..415a0d9 100755 --- a/scripts/toggle_logging.sh +++ b/scripts/toggle_logging.sh @@ -29,11 +29,15 @@ set_logging_variable() { tmux set-option -gq "@${pane_unique_id}" "$value" } -# this function checks if logging is happening for the current pane -is_logging() { +get_logging_variable() { 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 + echo $current_pane_logging +} + +# this function checks if logging is happening for the current pane +is_logging() { + if [ "$(get_logging_variable)" == "logging" ]; then return 0 else return 1 From d99a25a87e9211c960974699f8ebc86c06d28197 Mon Sep 17 00:00:00 2001 From: Phil Hindman Date: Sat, 28 Sep 2024 13:04:57 -0500 Subject: [PATCH 3/6] Simplify get/set logging variable Use a pane option variable, and remove unnecessary script variables. --- scripts/toggle_logging.sh | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/scripts/toggle_logging.sh b/scripts/toggle_logging.sh index 415a0d9..8691caa 100755 --- a/scripts/toggle_logging.sh +++ b/scripts/toggle_logging.sh @@ -17,22 +17,13 @@ stop_pipe_pane() { display_message "Ended logging to $logging_full_filename" } -# returns a string unique to current pane -pane_unique_id() { - tmux display-message -p "#{session_name}_#{window_index}_#{pane_index}" -} - # 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" + tmux set-option -pq @logging-variable "$1" } 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-variable } # this function checks if logging is happening for the current pane From 88bd8e171620c8b3dc9e44914d1abb838fd71108 Mon Sep 17 00:00:00 2001 From: Phil Hindman Date: Sat, 28 Sep 2024 13:11:22 -0500 Subject: [PATCH 4/6] Set/unset logging variable Set it in start_pipe_pane, unset it in stop_pipe_pane, and determine whether logging is on by whether it is set or unset. --- scripts/toggle_logging.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/toggle_logging.sh b/scripts/toggle_logging.sh index 8691caa..adc5626 100755 --- a/scripts/toggle_logging.sh +++ b/scripts/toggle_logging.sh @@ -10,11 +10,13 @@ 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 "logging" } stop_pipe_pane() { tmux pipe-pane display_message "Ended logging to $logging_full_filename" + unset_logging_variable } # saving 'logging' 'not logging' status in a variable unique to pane @@ -22,13 +24,17 @@ set_logging_variable() { tmux set-option -pq @logging-variable "$1" } +unset_logging_variable() { + tmux set-option -pu @logging-variable +} + get_logging_variable() { tmux show-option -pqv @logging-variable } # 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 @@ -38,10 +44,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 } From 5fad4879fb0f63196227aeef0f7704bb7c262d8b Mon Sep 17 00:00:00 2001 From: Phil Hindman Date: Sat, 28 Sep 2024 13:14:50 -0500 Subject: [PATCH 5/6] Store logging filename in @logging-variable Since the string stored in @logging-variable can be arbitrary, let's store the filename there, so that we can display the correct name when we stop logging. --- scripts/toggle_logging.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/toggle_logging.sh b/scripts/toggle_logging.sh index adc5626..c6004d7 100755 --- a/scripts/toggle_logging.sh +++ b/scripts/toggle_logging.sh @@ -10,12 +10,12 @@ 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 "logging" + 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 } From 5f03ad0fe2a17ffe44a2ad083844ed5698e857ea Mon Sep 17 00:00:00 2001 From: Phil Hindman Date: Sat, 28 Sep 2024 14:52:01 -0500 Subject: [PATCH 6/6] Rename functions/variables to reflect current usage The name of the file that the current pane is logging to is stored in the variable, so name it (and the helper functions) accordingly. --- scripts/toggle_logging.sh | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/scripts/toggle_logging.sh b/scripts/toggle_logging.sh index c6004d7..c0939d9 100755 --- a/scripts/toggle_logging.sh +++ b/scripts/toggle_logging.sh @@ -10,31 +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}" + set_active_logging_filename "${file}" } stop_pipe_pane() { tmux pipe-pane - display_message "Ended logging to $(get_logging_variable)" - unset_logging_variable + display_message "Ended logging to $(get_active_logging_filename)" + unset_active_logging_filename } -# saving 'logging' 'not logging' status in a variable unique to pane -set_logging_variable() { - tmux set-option -pq @logging-variable "$1" +set_active_logging_filename() { + tmux set-option -pq @active-logging-filename "$1" } -unset_logging_variable() { - tmux set-option -pu @logging-variable +unset_active_logging_filename() { + tmux set-option -pu @active-logging-filename } -get_logging_variable() { - tmux show-option -pqv @logging-variable +get_active_logging_filename() { + tmux show-option -pqv @active-logging-filename } # this function checks if logging is happening for the current pane is_logging() { - if [ -n "$(get_logging_variable)" ]; then + if [ -n "$(get_active_logging_filename)" ]; then return 0 else return 1