Files
dotfiles/zsh/kubernetes.zsh

73 lines
1.6 KiB
Bash

#
# Kubernetes Related
#
alias kc="kubectl"
alias hl="helm"
alias mk="minikube"
alias kctx="kubectx"
alias kns="kubens"
if command-exists kubectl; then
# lazy-load kubectl completion
_kubectl() {
unset -f _kubectl
eval "$(command kubectl completion zsh)"
}
switch() {
unset -f switch
source "$(brew --prefix switch)/switch.sh"
switch "$@"
}
export KREW_ROOT="$HOME/.krew"
path_append "${KREW_ROOT}/bin"
if ! command-exists kubectl-krew; then
krew-bin() {
echo "krew-$(uname | tr '[:upper:]' '[:lower:]')_$(uname -m | sed -e \
's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' \
-e 's/aarch64$/arm64/')"
}
zinit light-mode wait lucid as'null' from'gh-r' bpick'krew.tar.gz' \
atclone'KREW='"'$(krew-bin)'"' && ./$KREW install krew' \
for @kubernetes-sigs/krew
export KREW_ROOT="$HOME/.krew"
path_append "${KREW_ROOT}/bin"
fi
fi
_setup-kubectx-completion() {
local cmd="$1"
local dir="$HOME/.local/share/rtx/installs/kubectx/latest/completion"
local target="$ZSH_COMPLETIONS/_${cmd}"
if [ -f "$target" ] || [ ! -d "$dir" ]; then
return
fi
echo "Setting up completion for $cmd -- $target"
local script
if [ -f "${dir}/${cmd}.zsh" ]; then
script="$dir/${cmd}.zsh"
elif [ -f "${dir}/_${cmd}.zsh" ]; then
script="$dir/_${cmd}.zsh"
fi
echo " - Sym-linking from $script"
mkdir -p "$ZSH_COMPLETIONS"
ln -s "$script" "$target"
}
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