-
-
Save jordiclariana/b06f62ef90ac7171e7a1a6939b4e74e5 to your computer and use it in GitHub Desktop.
aliases for kubectl with autocomplete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source <(kubectl completion bash) | |
__start_kubectl_cust() | |
{ | |
local cur prev words cword | |
declare -A flaghash 2>/dev/null || : | |
if declare -F _init_completion >/dev/null 2>&1; then | |
_init_completion -s || return | |
else | |
__kubectl_init_completion -n "=" || return | |
fi | |
local c=0 | |
local flags=() | |
local two_word_flags=() | |
local local_nonpersistent_flags=() | |
local flags_with_completion=() | |
local flags_completion=() | |
local commands=() | |
local must_have_one_flag=() | |
local must_have_one_noun=() | |
local last_command="$1" | |
local nouns=() | |
__kubectl_handle_word | |
} | |
for cmd in kubectl_exec kubectl_delete_pod kubectl_describe kubectl_logs kubectl_port-forward; do | |
eval "__start_kubectl_$cmd(){ __start_kubectl_cust $cmd; }"; | |
done | |
complete -F __start_kubectl k | |
complete -F __start_kubectl_kubectl_exec kex | |
complete -F __start_kubectl_kubectl_delete_pod kdp | |
complete -F __start_kubectl_kubectl_describe kd | |
complete -F __start_kubectl_kubectl_logs kl | |
complete -F __start_kubectl_kubectl_port-forward kpf | |
alias k=kubectl | |
alias ksn='_f(){k get namespace $1 > /dev/null; if [ $? -eq 1 ]; then return $?; fi; k config set-context $(k config current-context) --namespace=$1; echo "Namespace: $1"};_f' | |
alias kex='_f(){ kubectl exec $1 -it -- bash; };_f' | |
alias kcc='kubectl config current-context' | |
alias kdp='kubectl delete po' | |
alias kgc='kubectl config get-contexts' | |
alias kge='kubectl get events --sort-by='\''{.lastTimestamp}'\' | |
alias kgp='kubectl get po' | |
alias kl='kubectl logs -f' | |
alias kd='kubectl describe' | |
alias kpf='kubectl port-forward' | |
alias ksc='kubectl config use-context' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment