1
0
Fork 0
mirror of https://github.com/pnx/dotfiles synced 2026-06-16 03:14:55 +02:00

scripts/tmuxs/kill.sh: switch to another session if we are killing the current one

This commit is contained in:
Henrik Hautakoski 2025-10-29 02:07:48 +01:00
parent c48615f0ae
commit 75fbfbc6e0

View file

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