Skip to content

Commit 80adb91

Browse files
committed
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).
1 parent 716b958 commit 80adb91

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

scripts/restore.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,15 @@ handle_session_0() {
292292
fi
293293
}
294294

295-
restore_pane_layout_for_each_window() {
295+
restore_pane_layout_and_autonaming_for_each_window() {
296296
\grep '^window' $(last_resurrect_file) |
297-
while IFS=$d read line_type session_name window_number window_active window_flags window_layout; do
297+
while IFS=$d read line_type session_name window_number window_active window_flags window_layout automatic_rename; do
298298
tmux select-layout -t "${session_name}:${window_number}" "$window_layout"
299+
if [ "${automatic_rename}" = ":" ]; then
300+
tmux set-option -u -t "${session_name}:${window_number}" automatic-rename
301+
else
302+
tmux set-option -t "${session_name}:${window_number}" automatic-rename "$automatic_rename"
303+
fi
299304
done
300305
}
301306

@@ -376,7 +381,7 @@ main() {
376381
execute_hook "pre-restore-all"
377382
restore_all_panes
378383
handle_session_0
379-
restore_pane_layout_for_each_window >/dev/null 2>&1
384+
restore_pane_layout_and_autonaming_for_each_window >/dev/null 2>&1
380385
execute_hook "pre-restore-history"
381386
if save_shell_history_option_on; then
382387
restore_shell_history

scripts/save.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,10 @@ dump_windows() {
245245
if is_session_grouped "$session_name"; then
246246
continue
247247
fi
248-
echo "${line_type}${d}${session_name}${d}${window_index}${d}${window_active}${d}${window_flags}${d}${window_layout}"
248+
automatic_rename="$(tmux show-window-options -vt "${session_name}:${window_index}" automatic-rename)"
249+
# If the option was unset, place the ":" placeholder instead.
250+
[ -z "${automatic_rename}" ] && automatic_rename=":"
251+
echo "${line_type}${d}${session_name}${d}${window_index}${d}${window_active}${d}${window_flags}${d}${window_layout}${d}${automatic_rename}"
249252
done
250253
}
251254

0 commit comments

Comments
 (0)