Skip to content

Commit

Permalink
Save logging filename in pane-specific variable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Phil Hindman committed Sep 28, 2024
1 parent 6455c71 commit 23dc333
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
24 changes: 9 additions & 15 deletions scripts/toggle_logging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit 23dc333

Please sign in to comment.