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 kdj='kubectl describe job'
alias kdelj='kubectl delete job' alias kdelj='kubectl delete job'
function kj() { kubectl "$@" -o json | jq; } # Utility print functions (json / yaml)
function kjx() { kubectl "$@" -o json | fx; } function _build_kubectl_out_alias {
function ky() { kubectl "$@" -o yaml | yh; } setopt localoptions norcexpandparam
if (( ${+functions[compdef]} )); then
compdef _kubectl kj # alias function
compdef _kubectl kjx eval "function $1 { $2 }"
compdef _kubectl ky
fi # 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