From 5f5f9d8fd5ff9769e5ef08d64a430ee7ab525dc7 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Mon, 3 Aug 2020 08:58:41 +0200 Subject: [PATCH] Kill session 0 if it's not restored --- CHANGELOG.md | 1 + scripts/restore.sh | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58b00a8..e1ac3cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - Enable vim session strategy to work with custom session files, e.g. `vim -S Session1.vim`. - Enable restoring command arguments for inline strategies with `*` character. +- Kill session "0" if it wasn't restored. ### v2.4.0, 2015-02-23 - add "tmux-test" diff --git a/scripts/restore.sh b/scripts/restore.sh index b1ed683..477951a 100755 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -76,6 +76,14 @@ is_restoring_pane_contents() { [ "$RESTORE_PANE_CONTENTS" == "true" ] } +restored_session_0_true() { + RESTORED_SESSION_0="true" +} + +has_restored_session_0() { + [ "$RESTORED_SESSION_0" == "true" ] +} + window_exists() { local session_name="$1" local window_number="$2" @@ -174,6 +182,9 @@ restore_pane() { dir="$(remove_first_char "$dir")" window_name="$(remove_first_char "$window_name")" pane_full_command="$(remove_first_char "$pane_full_command")" + if [ "$session_name" == "0" ]; then + restored_session_0_true + fi if pane_exists "$session_name" "$window_number" "$pane_index"; then tmux rename-window -t "$window_number" "$window_name" if is_restoring_from_scratch; then @@ -270,6 +281,16 @@ restore_all_panes() { fi } +handle_session_0() { + if is_restoring_from_scratch && ! has_restored_session_0; then + local current_session="$(tmux display -p "#{client_session}")" + if [ "$current_session" == "0" ]; then + tmux switch-client -n + fi + tmux kill-session -t "0" + fi +} + restore_pane_layout_for_each_window() { \grep '^window' $(last_resurrect_file) | while IFS=$d read line_type session_name window_number window_active window_flags window_layout; do @@ -353,6 +374,7 @@ main() { start_spinner "Restoring..." "Tmux restore complete!" execute_hook "pre-restore-all" restore_all_panes + handle_session_0 restore_pane_layout_for_each_window >/dev/null 2>&1 execute_hook "pre-restore-history" if save_shell_history_option_on; then