1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-12-18 10:22:00 +00:00

fix(kubectl): fix kubectl completion for kj, kjx and ky aliases (#12566)

This commit is contained in:
Marc Cornellà 2024-07-21 10:16:30 +02:00 committed by GitHub
parent b1e3a82bb5
commit 8127e5838c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -180,11 +180,23 @@ alias kej='kubectl edit job'
alias kdj='kubectl describe job'
alias kdelj='kubectl delete job'
function kj() { kubectl "$@" -o json | jq; }
function kjx() { kubectl "$@" -o json | fx; }
function ky() { kubectl "$@" -o yaml | yh; }
if (( ${+functions[compdef]} )); then
compdef _kubectl kj
compdef _kubectl kjx
compdef _kubectl ky
fi
# Utility print functions (json / yaml)
function _build_kubectl_out_alias {
setopt localoptions norcexpandparam
# alias function
eval "function $1 { $2 }"
# completion function
eval "function _$1 {
words=(kubectl \"\${words[@]:1}\")
_kubectl
}"
compdef _$1 $1
}
_build_kubectl_out_alias "kj" 'kubectl "$@" -o json | jq'
_build_kubectl_out_alias "kjx" 'kubectl "$@" -o json | fx'
_build_kubectl_out_alias "ky" 'kubectl "$@" -o yaml | yh'
unfunction _build_kubectl_out_alias