Update 05.04.2026

This commit is contained in:
eof
2026-04-05 17:51:45 +05:00
parent fcc904df1e
commit b363a93ea5
680 changed files with 16892 additions and 16586 deletions

View File

@@ -1,15 +1,17 @@
if (( $+commands[kubectl] )); then
# If the completion file does not exist, generate it and then source it
# Otherwise, source it and regenerate in the background
if [[ ! -f "$ZSH_CACHE_DIR/completions/_kubectl" ]]; then
kubectl completion zsh | tee "$ZSH_CACHE_DIR/completions/_kubectl" >/dev/null
source "$ZSH_CACHE_DIR/completions/_kubectl"
else
source "$ZSH_CACHE_DIR/completions/_kubectl"
kubectl completion zsh | tee "$ZSH_CACHE_DIR/completions/_kubectl" >/dev/null &|
fi
if (( ! $+commands[kubectl] )); then
return
fi
# 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
kubectl completion zsh 2> /dev/null >| "$ZSH_CACHE_DIR/completions/_kubectl" &|
# This command is used a LOT both below and in daily life
alias k=kubectl
@@ -19,6 +21,9 @@ alias kca='_kca(){ kubectl "$@" --all-namespaces; unset -f _kca; }; _kca'
# Apply a YML file
alias kaf='kubectl apply -f'
# Apply a kustomization directory
alias kapk='kubectl apply -k'
# Drop into an interactive terminal on a container
alias keti='kubectl exec -t -i'
@@ -34,9 +39,15 @@ alias kcgc='kubectl config get-contexts'
# General aliases
alias kdel='kubectl delete'
alias kdelf='kubectl delete -f'
alias kdelk='kubectl delete -k'
alias kge='kubectl get events --sort-by=".lastTimestamp"'
alias kgew='kubectl get events --sort-by=".lastTimestamp" --watch'
# Pod management.
alias kgp='kubectl get pods'
alias kgpl='kgp -l'
alias kgpn='kgp -n'
alias kgpsl='kubectl get pods --show-labels'
alias kgpa='kubectl get pods --all-namespaces'
alias kgpw='kgp --watch'
alias kgpwide='kgp -o wide'
@@ -45,12 +56,6 @@ alias kdp='kubectl describe pods'
alias kdelp='kubectl delete pods'
alias kgpall='kubectl get pods --all-namespaces -o wide'
# get pod by label: kgpl "app=myapp" -n myns
alias kgpl='kgp -l'
# get pod by namespace: kgpn kube-system"
alias kgpn='kgp -n'
# Service management.
alias kgs='kubectl get svc'
alias kgsa='kubectl get svc --all-namespaces'
@@ -97,6 +102,7 @@ alias kdd='kubectl describe deployment'
alias kdeld='kubectl delete deployment'
alias ksd='kubectl scale deployment'
alias krsd='kubectl rollout status deployment'
alias krrd='kubectl rollout restart deployment'
function kres(){
kubectl set env $@ REFRESHED_AT=$(date +%Y%m%d%H%M%S)
@@ -119,6 +125,7 @@ alias kdss='kubectl describe statefulset'
alias kdelss='kubectl delete statefulset'
alias ksss='kubectl scale statefulset'
alias krsss='kubectl rollout status statefulset'
alias krrss='kubectl rollout restart statefulset'
# Port forwarding
alias kpf="kubectl port-forward"
@@ -142,6 +149,7 @@ alias kcp='kubectl cp'
# Node Management
alias kgno='kubectl get nodes'
alias kgnosl='kubectl get nodes --show-labels'
alias keno='kubectl edit node'
alias kdno='kubectl describe node'
alias kdelno='kubectl delete node'
@@ -160,6 +168,7 @@ alias kdelsa="kubectl delete sa"
# DaemonSet management.
alias kgds='kubectl get daemonset'
alias kgdsa='kubectl get daemonset --all-namespaces'
alias kgdsw='kgds --watch'
alias keds='kubectl edit daemonset'
alias kdds='kubectl describe daemonset'
@@ -177,13 +186,23 @@ alias kej='kubectl edit job'
alias kdj='kubectl describe job'
alias kdelj='kubectl delete job'
# Only run if the user actually has kubectl installed
if (( ${+_comps[kubectl]} )); then
function kj() { kubectl "$@" -o json | jq; }
function kjx() { kubectl "$@" -o json | fx; }
function ky() { kubectl "$@" -o yaml | yh; }
# Utility print functions (json / yaml)
function _build_kubectl_out_alias {
setopt localoptions norcexpandparam
compdef kj=kubectl
compdef kjx=kubectl
compdef ky=kubectl
fi
# 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