From 1c298e9dbbee751d992f23d6df9b95e0cab3b915 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Sat, 6 Jul 2019 12:05:12 +0200 Subject: [PATCH] Fix: only first tmux client triggers save script Problem: if a user runs multiple tmux clients, all of the clients will trigger a save script at the same time. This may lead to corrupt 'last' files. To prevent this we're allowing only the first tmux client to perform saving. --- scripts/continuum_save.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/continuum_save.sh b/scripts/continuum_save.sh index c85f68a..5b7cc87 100755 --- a/scripts/continuum_save.sh +++ b/scripts/continuum_save.sh @@ -26,6 +26,12 @@ enough_time_since_last_run_passed() { [ "$(current_timestamp)" -ge "$next_run" ] } +first_client() { + local client_name="$(tmux display-message -p -F "#{client_name}")" + local first_client_name="$(tmux list-clients -F "#{client_name}" | head -n 1)" + [ "$client_name" == "$first_client_name" ] +} + fetch_and_run_tmux_resurrect_save_script() { local resurrect_save_script_path="$(get_tmux_option "$resurrect_save_path_option" "")" if [ -n "$resurrect_save_script_path" ]; then @@ -35,7 +41,7 @@ fetch_and_run_tmux_resurrect_save_script() { } main() { - if supported_tmux_version_ok && auto_save_not_disabled && enough_time_since_last_run_passed; then + if supported_tmux_version_ok && auto_save_not_disabled && enough_time_since_last_run_passed && first_client; then fetch_and_run_tmux_resurrect_save_script fi }