From f00dacf9a4ec15e8963ef10f47f0252bbc951628 Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Sun, 8 Mar 2026 23:52:25 -0700 Subject: [PATCH] fix: skip fzf launch when no contexts exist in kubeconfig Return an error early in InteractiveSwitchOp if the kubeconfig has no contexts, instead of launching fzf with an empty list. Co-Authored-By: Claude Opus 4.6 --- cmd/kubectx/fzf.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/kubectx/fzf.go b/cmd/kubectx/fzf.go index 56b33c9..9826009 100644 --- a/cmd/kubectx/fzf.go +++ b/cmd/kubectx/fzf.go @@ -52,6 +52,14 @@ func (op InteractiveSwitchOp) Run(_, stderr io.Writer) error { return fmt.Errorf("kubeconfig error: %w", err) } + ctxNames, err := kc.ContextNames() + if err != nil { + return fmt.Errorf("failed to get context names: %w", err) + } + if len(ctxNames) == 0 { + return errors.New("no contexts found in the kubeconfig file") + } + cmd := exec.Command("fzf", "--ansi", "--no-preview") var out bytes.Buffer cmd.Stdin = os.Stdin