Kill session 0 if it's not restored

pull/318/merge
Bruno Sutic 2020-08-03 08:58:41 +02:00
parent 78d67e4dcb
commit 5f5f9d8fd5
No known key found for this signature in database
GPG Key ID: CAFA7B1B2914ED81
2 changed files with 23 additions and 0 deletions

View File

@ -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"

View File

@ -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