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 May 18, 2024
1 parent 64ee986 commit a68ee0a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions scripts/toggle_logging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ 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)"
set_logging_variable ""
}

# 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
# saving value in a variable unique to pane
set_logging_variable() {
local value="$1"
local pane_unique_id="$(pane_unique_id)"
Expand All @@ -31,13 +33,13 @@ set_logging_variable() {

get_logging_variable() {
local pane_unique_id="$(pane_unique_id)"
local current_pane_logging="$(get_tmux_option "@${pane_unique_id}" "not logging")"
local current_pane_logging="$(get_tmux_option "@${pane_unique_id}")"
echo $current_pane_logging
}

# 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 +49,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

0 comments on commit a68ee0a

Please sign in to comment.