From 75fbfbc6e0a5b4d15069e9b780599028c9c71b36 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Wed, 29 Oct 2025 02:07:48 +0100 Subject: [PATCH] scripts/tmuxs/kill.sh: switch to another session if we are killing the current one --- scripts/tmuxs/kill.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/tmuxs/kill.sh b/scripts/tmuxs/kill.sh index f27d39b..672c5af 100755 --- a/scripts/tmuxs/kill.sh +++ b/scripts/tmuxs/kill.sh @@ -1,2 +1,14 @@ #!/usr/bin/env bash -tmux kill-session -t $(echo $@ | sed 's/: .*//g') + +SESSION=$(echo $@ | sed 's/: .*//g') +CURRENT=$(tmux list-sessions -F "#{session_name}" -f "#{session_attached}" | head -n 1) + +# If we are killing the current session. Move to another +if [ "$CURRENT" == "$SESSION" ]; then + NEXT=$(tmux list-sessions -F "#{session_name}" -f "#{==:#{session_attached},0}" | head -n 1) + if [ ! -z "$NEXT" ]; then + tmux switch -t "${NEXT}" + fi +fi + +tmux kill-session -t "$SESSION"