Skip to content

Commit f47fee6

Browse files
committed
Resurrect window options
1 parent dc14383 commit f47fee6

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

scripts/restore.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,31 @@ restore_session_options() {
370370
done
371371
}
372372

373+
restore_window_options() {
374+
local has_automatic_rename="${d}"
375+
while IFS=$d read line_type session_name window_index option value; do
376+
value=$(echo $value | sed 's/"\(.*\)"/\1/')
377+
if [ "$option" == "automatic-rename" ]; then
378+
has_automatic_rename+="${session_name}:${window_index}${d}"
379+
fi
380+
tmux set-window-option -t "${session_name}:${window_index}" "${option}" "${value}"
381+
done <<< $(\grep '^option_window' $(last_resurrect_file))
382+
383+
get_grouped_sessions "$(\grep '^grouped_session\s' $(last_resurrect_file))"
384+
get_linked_windows "$(\grep '^linked_window\s' $(last_resurrect_file))"
385+
386+
tmux list-windows -a -F "#{session_name}${d}#{window_index}" |
387+
while IFS=$d read session_name window_index ;do
388+
if is_session_grouped "$session_name" || is_window_linked "$session_name" "$window_index"; then
389+
continue
390+
fi
391+
392+
if [[ "$has_automatic_rename" != *"$session_name:$window_index"* ]]; then
393+
tmux set-window-option -u -t "$session_name:$window_index" "automatic-rename"
394+
fi
395+
done
396+
}
397+
373398
# A cleanup that happens after 'restore_all_panes' seems to fix fish shell
374399
# users' restore problems.
375400
cleanup_restored_pane_contents() {
@@ -395,6 +420,7 @@ main() {
395420
restore_active_and_alternate_windows
396421
restore_active_and_alternate_sessions
397422
restore_session_options
423+
restore_window_options
398424
cleanup_restored_pane_contents
399425
execute_hook "post-restore-all"
400426
stop_spinner

scripts/save.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ state_format() {
9393
echo "$format"
9494
}
9595

96+
window_option_format() {
97+
local format
98+
format+="option_window"
99+
format+="${delimiter}"
100+
format+="#{session_name}"
101+
format+="${delimiter}"
102+
format+="#{window_index}"
103+
echo "$format"
104+
}
105+
96106
dump_panes_raw() {
97107
tmux list-panes -a -F "$(pane_format)"
98108
}
@@ -268,6 +278,19 @@ dump_session_options() {
268278
done
269279
}
270280

281+
dump_window_options() {
282+
tmux list-windows -a -F "$(window_option_format)" |
283+
while IFS=$d read line_type session_name window_index; do
284+
if is_session_grouped "${session_name}" || is_window_linked "$session_name" "$window_index"; then
285+
continue
286+
fi
287+
tmux show-window-options -t "${session_name}:${window_index}" | sed "s/ /$d/" |
288+
while IFS=$d read option value; do
289+
echo "${line_type}${d}${session_name}${d}${window_index}${d}${option}$d${value}"
290+
done
291+
done
292+
}
293+
271294
dump_state() {
272295
tmux display-message -p "$(state_format)"
273296
}
@@ -302,6 +325,7 @@ save_all() {
302325
dump_windows >> "$resurrect_file_path"
303326
dump_state >> "$resurrect_file_path"
304327
dump_session_options >> "$resurrect_file_path"
328+
dump_window_options >> "$resurrect_file_path"
305329
execute_hook "post-save-layout" "$resurrect_file_path"
306330
if files_differ "$resurrect_file_path" "$last_resurrect_file"; then
307331
ln -fs "$(basename "$resurrect_file_path")" "$last_resurrect_file"

0 commit comments

Comments
 (0)