From b502572a074e55a69211844339c1c79dcfe0bdf9 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Mon, 9 Feb 2015 16:11:49 +0100 Subject: [PATCH] Restore active and alternate windows only if they are present in the 'last' file --- CHANGELOG.md | 1 + scripts/restore.sh | 10 ++++++++-- scripts/save.sh | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 192c1f8..5f2dea5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - save and restore grouped sessions (used with multi-monitor workflow) - save and restore active and alternate windows in grouped sessions - if there are no grouped sessions, do not output empty line to "last" file +- restore active and alternate windows only if they are present in the "last" file ### v1.5.0, 2014-11-09 - add support for restoring neovim sessions diff --git a/scripts/restore.sh b/scripts/restore.sh index ba0079d..2a35313 100755 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -195,8 +195,14 @@ 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}" + alternate_window_index="$(remove_first_char "$alternate_window_index")" + active_window_index="$(remove_first_char "$active_window_index")" + if [ -n "$alternate_window_index" ]; then + tmux switch-client -t "${grouped_session}:${alternate_window_index}" + fi + if [ -n "$active_window_index" ]; then + tmux switch-client -t "${grouped_session}:${active_window_index}" + fi done } diff --git a/scripts/save.sh b/scripts/save.sh index 4373bcd..16c3f2f 100755 --- a/scripts/save.sh +++ b/scripts/save.sh @@ -142,7 +142,7 @@ dump_grouped_sessions() { # this session "points" to the 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}" + echo "grouped_session${d}${session_name}${d}${original_session}${d}:${alternate_window_index}${d}:${active_window_index}" fi done }