diff --git a/CHANGELOG.md b/CHANGELOG.md index 1817294..9ad2ffa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - add link to the wiki page for "first pane/window issue" to the README as well as other tweaks - save and restore grouped sessions (used with multi-monitor workflow) +- save and restore active and alternate windows in grouped sessions ### v1.5.0, 2014-11-09 - add support for restoring neovim sessions diff --git a/scripts/restore.sh b/scripts/restore.sh index 11bd3eb..ba0079d 100755 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -186,15 +186,25 @@ restore_active_pane_for_each_window() { restore_grouped_session() { local grouped_session="$1" echo "$grouped_session" | - while IFS=$'\t' read line_type grouped_session original_session; do + while IFS=$'\t' read line_type grouped_session original_session alternate_window active_window; do TMUX="" tmux -S "$(tmux_socket)" new-session -d -s "$grouped_session" -t "$original_session" done } +restore_active_and_alternate_windows_for_grouped_sessions() { + local grouped_session="$1" + echo "$grouped_session" | + while IFS=$'\t' read line_type grouped_session original_session alternate_window_index active_window_index; do + tmux switch-client -t "${grouped_session}:${alternate_window_index}" + tmux switch-client -t "${grouped_session}:${active_window_index}" + done +} + restore_grouped_sessions() { while read line; do if is_line_type "grouped_session" "$line"; then restore_grouped_session "$line" + restore_active_and_alternate_windows_for_grouped_sessions "$line" fi done < $(last_resurrect_file) } @@ -227,7 +237,7 @@ main() { # below functions restore exact cursor positions restore_active_pane_for_each_window restore_zoomed_windows - restore_grouped_sessions + restore_grouped_sessions # also restores active and alt windows for grouped sessions restore_active_and_alternate_windows restore_active_and_alternate_sessions stop_spinner diff --git a/scripts/save.sh b/scripts/save.sh index 0ed1538..66ba70f 100755 --- a/scripts/save.sh +++ b/scripts/save.sh @@ -114,6 +114,18 @@ save_shell_history() { fi } +get_active_window_index() { + local session_name="$1" + tmux list-windows -t "$session_name" -F "#{window_flags} #{window_index}" | + awk '$1 ~ /\*/ { print $2; }' +} + +get_alternate_window_index() { + local session_name="$1" + tmux list-windows -t "$session_name" -F "#{window_flags} #{window_index}" | + awk '$1 ~ /-/ { print $2; }' +} + dump_grouped_sessions() { local current_session_group="" local original_session @@ -128,7 +140,9 @@ dump_grouped_sessions() { current_session_group="$session_group" else # this session "points" to the original session - echo "grouped_session${d}${session_name}${d}${original_session}" + active_window_index="$(get_active_window_index "$session_name")" + alternate_window_index="$(get_alternate_window_index "$session_name")" + echo "grouped_session${d}${session_name}${d}${original_session}${d}${alternate_window_index}${d}${active_window_index}" fi done }