Skip to content

Commit 5f5f9d8

Browse files
committed
Kill session 0 if it's not restored
1 parent 78d67e4 commit 5f5f9d8

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- Enable vim session strategy to work with custom session files,
3030
e.g. `vim -S Session1.vim`.
3131
- Enable restoring command arguments for inline strategies with `*` character.
32+
- Kill session "0" if it wasn't restored.
3233

3334
### v2.4.0, 2015-02-23
3435
- add "tmux-test"

scripts/restore.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ is_restoring_pane_contents() {
7676
[ "$RESTORE_PANE_CONTENTS" == "true" ]
7777
}
7878

79+
restored_session_0_true() {
80+
RESTORED_SESSION_0="true"
81+
}
82+
83+
has_restored_session_0() {
84+
[ "$RESTORED_SESSION_0" == "true" ]
85+
}
86+
7987
window_exists() {
8088
local session_name="$1"
8189
local window_number="$2"
@@ -174,6 +182,9 @@ restore_pane() {
174182
dir="$(remove_first_char "$dir")"
175183
window_name="$(remove_first_char "$window_name")"
176184
pane_full_command="$(remove_first_char "$pane_full_command")"
185+
if [ "$session_name" == "0" ]; then
186+
restored_session_0_true
187+
fi
177188
if pane_exists "$session_name" "$window_number" "$pane_index"; then
178189
tmux rename-window -t "$window_number" "$window_name"
179190
if is_restoring_from_scratch; then
@@ -270,6 +281,16 @@ restore_all_panes() {
270281
fi
271282
}
272283

284+
handle_session_0() {
285+
if is_restoring_from_scratch && ! has_restored_session_0; then
286+
local current_session="$(tmux display -p "#{client_session}")"
287+
if [ "$current_session" == "0" ]; then
288+
tmux switch-client -n
289+
fi
290+
tmux kill-session -t "0"
291+
fi
292+
}
293+
273294
restore_pane_layout_for_each_window() {
274295
\grep '^window' $(last_resurrect_file) |
275296
while IFS=$d read line_type session_name window_number window_active window_flags window_layout; do
@@ -353,6 +374,7 @@ main() {
353374
start_spinner "Restoring..." "Tmux restore complete!"
354375
execute_hook "pre-restore-all"
355376
restore_all_panes
377+
handle_session_0
356378
restore_pane_layout_for_each_window >/dev/null 2>&1
357379
execute_hook "pre-restore-history"
358380
if save_shell_history_option_on; then

0 commit comments

Comments
 (0)