diff --git a/zsh/kubernetes.zsh b/zsh/kubernetes.zsh index a6527d4..80ec7fa 100644 --- a/zsh/kubernetes.zsh +++ b/zsh/kubernetes.zsh @@ -5,6 +5,8 @@ alias kc="kubectl" alias hl="helm" alias mk="minikube" +alias kctx="kubectx" +alias kns="kubens" if command-exists kubectl; then # lazy-load kubectl completion @@ -19,9 +21,6 @@ if command-exists kubectl; then switch "$@" } - zinit light-mode wait lucid as'program' from'gh-r' \ - for @stackrox/kube-linter - export KREW_ROOT="$HOME/.krew" path_append "${KREW_ROOT}/bin" @@ -39,23 +38,33 @@ if command-exists kubectl; then export KREW_ROOT="$HOME/.krew" path_append "${KREW_ROOT}/bin" fi - - zinit light-mode wait lucid as'program' from'gh-r' mv'kind-* -> kind' \ - atclone'./kind completion zsh > _kind' atpull'%atclone' \ - for @kubernetes-sigs/kind - - zinit light-mode wait lucid as'program' from'gh-r' \ - atclone'./flux completion zsh > _flux' atpull'%atclone' \ - for @fluxcd/flux2 - - zinit light-mode wait lucid as'program' from'gh-r' \ - atclone'./kustomize completion zsh > _kustomize' atpull'%atclone' \ - for @kubernetes-sigs/kustomize - - zinit light-mode wait lucid as'program' from'gh-r' pick'kubeseal' \ - for @bitnami-labs/sealed-secrets - - zinit light-mode wait lucid as'program' from'gh-r' mv'argocd-* -> argocd' \ - atclone'./argocd completion zsh > _argocd' atpull'%atclone' \ - for @argoproj/argo-cd +fi + +_setup-kubectx-completion() { + local cmd="$1" + local dir="$HOME/.local/share/rtx/installs/kubectx/latest/completion/" + + if [ -f "$ZSH_COMPLETIONS/_${cmd}" ] || [ !-d "$dir" ]; then + return + fi + + echo "Setting up completion for $cmd -- $ZSH_COMPLETIONS/_${cmd}" + + local script + if [ -f "${dir}/${cmd}.zsh" ]; then + script="$dir/${cmd}.zsh" + elif [ -f "${dir}/_${cmd}.zsh" ]; then + script="$dir/_${cmd}.zsh" + fi + + mkdir -p "$ZSH_COMPLETIONS" + ln -s "$script" "$ZSH_COMPLETIONS/_${cmd}" +} + +if command-exists kubectx && ! which _kubectx &> /dev/null; then + _setup-kubectx-completion kubectx +fi + +if command-exists kubens && ! which _kubens &> /dev/null; then + _setup-kubectx-completion kubens fi diff --git a/zshenv b/zshenv index 6aa5397..a715af3 100644 --- a/zshenv +++ b/zshenv @@ -90,6 +90,9 @@ if [[ "$TMPDIR" == "/var/folders/"* ]] || [[ "$TMPDIR" == "" ]]; then mkdir -p "$TMPDIR" fi +export DOTZSH_SITEFUNS="$DOTZSH/site-functions" +export ZSH_COMPLETIONS="$HOME/.local/share/zsh/completions" + # Ensure basic systems paths are in desired order path_prepend "/bin" path_prepend "/sbin" diff --git a/zshrc b/zshrc index 68b3bcf..0632213 100644 --- a/zshrc +++ b/zshrc @@ -66,6 +66,9 @@ zstyle ':completion:*:descriptions' format '%B%d%b' zstyle ':completion:*:make:*:targets' call-command true zstyle ':completion:*:make:*' tag-order targets +if [ -d "$ZSH_COMPLETIONS" ]; then fpath=("$ZSH_COMPLETIONS" $fpath); fi +if [ -d "$DOTZSH_SITEFUNS" ]; then fpath=("$DOTZSH_SITEFUNS" $fpath); fi + # ============================================================================== # Edit command line # ============================================================================== @@ -167,8 +170,4 @@ if [ -f "$HOME/.zshrc.local" ]; then source "$HOME/.zshrc.local" fi -if [ -d "$DOTZSH/site-functions" ]; then - fpath=("$DOTZSH/site-functions" $fpath) -fi - autoload -U +X bashcompinit && bashcompinit