From ad52ade4bfd14c3f10dfb7b70ef79ac9ca880903 Mon Sep 17 00:00:00 2001 From: Arno Mayrhofer Date: Sat, 25 Oct 2014 01:12:39 +0200 Subject: [PATCH] Preserving layout of zoomed windows across restores The problem is that tmux list-window shows only the current pane layout if a pane is maximized. This is a bug in tmux. In order to avoid this bug we unzoom the window when saving and zoom in again after saving. This implies that the Z flag is no longer set in list-windows, and so it can't be used when restoring. Instead we use the Z flag of the panes (which still have it) to restore the zoom. --- scripts/helpers.sh | 7 +++++++ scripts/restore.sh | 7 ------- scripts/save.sh | 9 +++++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/scripts/helpers.sh b/scripts/helpers.sh index 1cb9fd1..59a9d1c 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -73,3 +73,10 @@ resurrect_history_file() { local pane_id="$1" echo "$(resurrect_dir)/bash_history-${pane_id}" } + +restore_zoomed_windows() { + awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $6 ~ /Z/ && $9 == 1 { print $2, $3; }' $(last_resurrect_file) | + while IFS=$'\t' read session_name window_number; do + tmux resize-pane -t "${session_name}:${window_number}" -Z + done +} diff --git a/scripts/restore.sh b/scripts/restore.sh index 6dd1707..8ef24f2 100755 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -183,13 +183,6 @@ restore_active_pane_for_each_window() { done } -restore_zoomed_windows() { - awk 'BEGIN { FS="\t"; OFS="\t" } /^window/ && $5 ~ /Z/ { print $2, $3; }' $(last_resurrect_file) | - while IFS=$'\t' read session_name window_number; do - tmux resize-pane -t "${session_name}:${window_number}" -Z - done -} - restore_active_and_alternate_windows() { awk 'BEGIN { FS="\t"; OFS="\t" } /^window/ && $5 ~ /[*-]/ { print $2, $4, $3; }' $(last_resurrect_file) | sort -u | diff --git a/scripts/save.sh b/scripts/save.sh index 07e3d29..612d7a0 100755 --- a/scripts/save.sh +++ b/scripts/save.sh @@ -100,8 +100,16 @@ save_shell_history() { dump_panes() { local full_command local d=$'\t' # delimiter + local last_resized="none-resized" dump_panes_raw | while IFS=$'\t' read line_type session_name window_number window_name window_active window_flags pane_index dir pane_active pane_command pane_pid; do + # check if current pane is part of a maximized window and if we haven't maximized it already + if [[ "${window_flags}" == *Z* ]] && [[ "${last_resized}" != ${window_number} ]]; then + # unmaximize the pane + tmux resize-pane -Z -t "${session_name}:${window_number}" + # set last resized window to current number in order to avoid maximizing again + last_resized=${window_number} + fi full_command="$(pane_full_command $pane_pid)" echo "${line_type}${d}${session_name}${d}${window_number}${d}${window_name}${d}${window_active}${d}${window_flags}${d}${pane_index}${d}${dir}${d}${pane_active}${d}${pane_command}${d}:${full_command}" done @@ -132,6 +140,7 @@ save_all() { if save_bash_history_option_on; then dump_bash_history fi + restore_zoomed_windows } main() {