1
0
Fork 0
dotfiles/.config/zsh/completions/_kube

41 lines
1.1 KiB
Plaintext

#compdef kube
local curcontext="$curcontext" state line expl ret=1
function _kube_clusters() {
find "$TRALIOS_KUBECONFIG_DIR" \
-maxdepth 1 \
-type f \
-regex ".*\.ya?ml" |
xargs -n 1 basename |
sed 's/\.ya\?ml$//'
}
function _kube_args() {
index=$1
kubeconfig=$(find "$TRALIOS_KUBECONFIG_DIR" -maxdepth 1 -type f -regex ".*/${words[3]}\.ya?ml")
case "${words[2]}" in
(shell)
case "$index" in
(3)
kubectl --kubeconfig "${kubeconfig}" get namespaces | tail -n +2 | awk "{ print \$1 }"
;;
(4)
kubectl --kubeconfig "${kubeconfig}" -n "${words[4]}" get pods | tail -n +2 | awk "{ print \$1 }"
;;
esac
;;
(pv_migrate)
if [ "$index" = "3" ]; then
_kube_clusters
fi
;;
esac
}
_arguments '1:action:(shell k9s ctl dash prom traefik rook debug_start debug_kill pv_migrate)'
_arguments '2:cluster:($(_kube_clusters))'
_arguments '3:arguments:($(_kube_args 3))'
_arguments '4:arguments:($(_kube_args 4))'