From 80adb917c1128b9dd701e8f542632dea23b39838 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Mon, 23 Aug 2021 13:55:19 +0900 Subject: [PATCH] Maintain the value of automatic-rename When the session is restored, the windows are renamed to their original names switching off automatic-rename, which can be undesirable. Therefore the value of automatic-rename is now saved for each window and restored after the renaming. If the value is set, that value is saved and then applied. Otherwise, a placeholder of ':' is placed instead, in which case the local option is unset for that window (as it originally was). --- scripts/restore.sh | 11 ++++++++--- scripts/save.sh | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/restore.sh b/scripts/restore.sh index 373a210..9b95527 100755 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -292,10 +292,15 @@ handle_session_0() { fi } -restore_pane_layout_for_each_window() { +restore_pane_layout_and_autonaming_for_each_window() { \grep '^window' $(last_resurrect_file) | - while IFS=$d read line_type session_name window_number window_active window_flags window_layout; do + while IFS=$d read line_type session_name window_number window_active window_flags window_layout automatic_rename; do tmux select-layout -t "${session_name}:${window_number}" "$window_layout" + if [ "${automatic_rename}" = ":" ]; then + tmux set-option -u -t "${session_name}:${window_number}" automatic-rename + else + tmux set-option -t "${session_name}:${window_number}" automatic-rename "$automatic_rename" + fi done } @@ -376,7 +381,7 @@ main() { execute_hook "pre-restore-all" restore_all_panes handle_session_0 - restore_pane_layout_for_each_window >/dev/null 2>&1 + restore_pane_layout_and_autonaming_for_each_window >/dev/null 2>&1 execute_hook "pre-restore-history" if save_shell_history_option_on; then restore_shell_history diff --git a/scripts/save.sh b/scripts/save.sh index 08647a7..85b9765 100755 --- a/scripts/save.sh +++ b/scripts/save.sh @@ -245,7 +245,10 @@ dump_windows() { if is_session_grouped "$session_name"; then continue fi - echo "${line_type}${d}${session_name}${d}${window_index}${d}${window_active}${d}${window_flags}${d}${window_layout}" + automatic_rename="$(tmux show-window-options -vt "${session_name}:${window_index}" automatic-rename)" + # If the option was unset, place the ":" placeholder instead. + [ -z "${automatic_rename}" ] && automatic_rename=":" + echo "${line_type}${d}${session_name}${d}${window_index}${d}${window_active}${d}${window_flags}${d}${window_layout}${d}${automatic_rename}" done }