From 1e511d8c5c231c9cceed9c722f4046921d8a5784 Mon Sep 17 00:00:00 2001 From: Jans Rautenbach Date: Wed, 16 Jul 2025 10:53:31 +0200 Subject: [PATCH] feat(kubectl): get and set current context namespace Signed-off-by: Jans Rautenbach --- plugins/kubectl/README.md | 4 +++- plugins/kubectl/kubectl.plugin.zsh | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/kubectl/README.md b/plugins/kubectl/README.md index 6f347a8ee..1b8ee7186 100644 --- a/plugins/kubectl/README.md +++ b/plugins/kubectl/README.md @@ -23,11 +23,13 @@ plugins=(... kubectl) | kcdc | `kubectl config delete-context` | Delete the specified context from the kubeconfig | | kccc | `kubectl config current-context` | Display the current-context | | kcgc | `kubectl config get-contexts` | List of contexts available | +| kcsetns | `kcsc --current --namespace` | Update the current context namespace | +| kcgetns | `k config view --minify -o jsonpath=...` | Get the current context namespace | | | | **General aliases** | | kdel | `kubectl delete` | Delete resources by filenames, stdin, resources and names, or by resources and label selector | | kdelf | `kubectl delete -f` | Delete a pod using the type and name specified in -f argument | | kge | `kubectl get events --sort-by=".lastTimestamp"` | Get events (sorted by timestamp) | -| kgew | `kubectl get events --watch --sort-by=".lastTimestamp"` | Get events and watch as they occur (sorted by timestamp) | +| kgew | `kubectl get events --watch --sort-by=".lastTimestamp"` | Get events and watch as they occur (sorted by timestamp) | | | | **Pod management** | | kgp | `kubectl get pods` | List all pods in ps output format | | kgpl | `kgp -l` | Get pods by label. Example: `kgpl "app=myapp" -n myns` | diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh index 4a72c02af..dbdb81af8 100644 --- a/plugins/kubectl/kubectl.plugin.zsh +++ b/plugins/kubectl/kubectl.plugin.zsh @@ -24,11 +24,13 @@ alias kaf='kubectl apply -f' # Drop into an interactive terminal on a container alias keti='kubectl exec -t -i' -# Manage configuration quickly to switch contexts between local, dev ad staging. +# Manage configuration quickly to switch contexts between local, dev and staging. alias kcuc='kubectl config use-context' alias kcsc='kubectl config set-context' alias kcdc='kubectl config delete-context' alias kccc='kubectl config current-context' +alias kcsetns="kcsc --current --namespace" +alias kcgetns="k config view --minify -o 'jsonpath={.contexts[0].context.namespace}'" # List all contexts alias kcgc='kubectl config get-contexts'