mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-19 21:41:07 +01:00
refactor(kubectl): optimize completion generation
This commit is contained in:
parent
d3bb52d7d8
commit
7ae4f76f6d
1 changed files with 21 additions and 11 deletions
|
@ -1,13 +1,22 @@
|
|||
if (( $+commands[kubectl] )); then
|
||||
__KUBECTL_COMPLETION_FILE="${ZSH_CACHE_DIR}/kubectl_completion"
|
||||
# TODO: 2022-01-05: remove this block
|
||||
# remove old generated files
|
||||
command rm -f "$ZSH_CACHE_DIR/kubectl_completion"
|
||||
|
||||
if [[ ! -f $__KUBECTL_COMPLETION_FILE || ! -s $__KUBECTL_COMPLETION_FILE ]]; then
|
||||
kubectl completion zsh >! $__KUBECTL_COMPLETION_FILE
|
||||
# TODO: 2022-01-05: remove this bit of code as it exists in oh-my-zsh.sh
|
||||
# Add completions folder in $ZSH_CACHE_DIR
|
||||
command mkdir -p "$ZSH_CACHE_DIR/completions"
|
||||
(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
|
||||
|
||||
# If the completion file doesn't exist yet, we need to autoload it and
|
||||
# bind it to `kubectl`. Otherwise, compinit will have already done that.
|
||||
if [[ ! -f "$ZSH_CACHE_DIR/completions/_kubectl" ]]; then
|
||||
typeset -g -A _comps
|
||||
autoload -Uz _kubectl
|
||||
_comps[kubectl]=_kubectl
|
||||
fi
|
||||
|
||||
[[ -f $__KUBECTL_COMPLETION_FILE ]] && source $__KUBECTL_COMPLETION_FILE
|
||||
|
||||
unset __KUBECTL_COMPLETION_FILE
|
||||
kubectl completion zsh >! "$ZSH_CACHE_DIR/completions/_kubectl" &|
|
||||
fi
|
||||
|
||||
# This command is used a LOT both below and in daily life
|
||||
|
@ -97,7 +106,8 @@ alias kdd='kubectl describe deployment'
|
|||
alias kdeld='kubectl delete deployment'
|
||||
alias ksd='kubectl scale deployment'
|
||||
alias krsd='kubectl rollout status deployment'
|
||||
kres(){
|
||||
|
||||
function kres(){
|
||||
kubectl set env $@ REFRESHED_AT=$(date +%Y%m%d%H%M%S)
|
||||
}
|
||||
|
||||
|
@ -170,9 +180,9 @@ alias kdelcj='kubectl delete cronjob'
|
|||
|
||||
# Only run if the user actually has kubectl installed
|
||||
if (( ${+_comps[kubectl]} )); then
|
||||
kj() { kubectl "$@" -o json | jq; }
|
||||
kjx() { kubectl "$@" -o json | fx; }
|
||||
ky() { kubectl "$@" -o yaml | yh; }
|
||||
function kj() { kubectl "$@" -o json | jq; }
|
||||
function kjx() { kubectl "$@" -o json | fx; }
|
||||
function ky() { kubectl "$@" -o yaml | yh; }
|
||||
|
||||
compdef kj=kubectl
|
||||
compdef kjx=kubectl
|
||||
|
|
Loading…
Reference in a new issue