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).
This commit is contained in:
A Farzat 2021-08-23 13:55:19 +09:00
parent 716b958145
commit 80adb917c1
2 changed files with 12 additions and 4 deletions

View File

@ -292,10 +292,15 @@ handle_session_0() {
fi fi
} }
restore_pane_layout_for_each_window() { restore_pane_layout_and_autonaming_for_each_window() {
\grep '^window' $(last_resurrect_file) | \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" 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 done
} }
@ -376,7 +381,7 @@ main() {
execute_hook "pre-restore-all" execute_hook "pre-restore-all"
restore_all_panes restore_all_panes
handle_session_0 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" execute_hook "pre-restore-history"
if save_shell_history_option_on; then if save_shell_history_option_on; then
restore_shell_history restore_shell_history

View File

@ -245,7 +245,10 @@ dump_windows() {
if is_session_grouped "$session_name"; then if is_session_grouped "$session_name"; then
continue continue
fi 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 done
} }