Skip to content

Commit

Permalink
fix(kubectl): fix kubectl completion for kj, kjx and ky aliases (
Browse files Browse the repository at this point in the history
  • Loading branch information
mcornella authored Jul 21, 2024
1 parent b1e3a82 commit 8127e58
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions plugins/kubectl/kubectl.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8127e58

Please sign in to comment.