From 77ab262c4392f291d28ec8077b5173caa2198532 Mon Sep 17 00:00:00 2001 From: Bryan Joshua Pedini Date: Tue, 14 Apr 2026 15:16:15 +0200 Subject: [PATCH] added kubernetes aliases and help functions --- bashrc_overrides/kubernetes | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 bashrc_overrides/kubernetes diff --git a/bashrc_overrides/kubernetes b/bashrc_overrides/kubernetes new file mode 100644 index 0000000..76f4321 --- /dev/null +++ b/bashrc_overrides/kubernetes @@ -0,0 +1,25 @@ +source <(kubectl completion bash) +alias k="kubectl" +alias kcontext="kubectl config use-context" +kns() { + if [[ $# -eq 0 ]]; then + printf '%s\n' "$(kubectl config view --minify -o jsonpath='{.contexts[0].context.namespace}')" + else + local ns="${1?Namespace required}" + kubectl config set-context --current --namespace "$ns" + printf 'Switched current context to namespace: %s\n' "$ns" + fi +} +_kns_completion() { + local cur + cur=${COMP_WORDS[COMP_CWORD]} + COMPREPLY=( $(compgen -W "$(kubectl get namespaces -o name | sed 's|namespace/||')" -- "$cur") ) +} +_kcontext_completion() { + local cur + cur=${COMP_WORDS[COMP_CWORD]} + COMPREPLY=( $(compgen -W "$(kubectl config get-contexts -o name)" -- $cur) ) +} +complete -F __start_kubectl k +complete -F _kns_completion kns +complete -F _kcontext_completion kcontext