From 8546ac9bf25d8a480d4841921030519fd2d0ee0a Mon Sep 17 00:00:00 2001 From: Stefan Koelle Date: Sun, 9 Aug 2026 20:45:44 +0200 Subject: [PATCH] Fix: kill stale tmux session as separate command, not in chain tmux aborts the entire command chain when kill-session fails (no existing session). This caused 'no current target' error on Linux. The kill-session is now a separate exec.Command() call before starting the tmux chain, ignoring any error. --- SPEC.md | 3 ++- cmd/kctl-tui/full.go | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/SPEC.md b/SPEC.md index fbfd1c3..55f3d8c 100644 --- a/SPEC.md +++ b/SPEC.md @@ -89,7 +89,8 @@ not cover: **redeploy** and **secrets diff**. Example startup command (generic placeholders): ``` -tmux kill-session -t kctl \; \ +# Kill stale session first (separate command — tmux aborts on kill-session error). +tmux kill-session -t kctl tmux new-session -d -s kctl \ -- "kctl-tui panel --context=$CTX_A --ns=$NS --team=$TEAM" \; \ set-option -t kctl remain-on-exit on \; \ diff --git a/cmd/kctl-tui/full.go b/cmd/kctl-tui/full.go index cfd1cfb..236b46d 100644 --- a/cmd/kctl-tui/full.go +++ b/cmd/kctl-tui/full.go @@ -277,8 +277,10 @@ func (m *fullModel) startTmuxSession() tea.Cmd { ctxA := m.cfg.ResolveContext(envA, m.selectedContext) k9sCmdA := fmt.Sprintf("k9s --context %s -n %s", ctxA, m.selectedNamespace) + // Kill stale session first (ignore error if none exists). + exec.Command("tmux", "kill-session", "-t", "kctl").Run() + args := []string{ - "kill-session", "-t", "kctl", ";", // ignore error if no session exists "new-session", "-d", "-s", "kctl", "--", panelCmd, ";", "set-option", "-t", "kctl", "remain-on-exit", "on", ";",