Skip to content

Instantly share code, notes, and snippets.

@kaiix
Last active December 27, 2018 03:50
Show Gist options
  • Save kaiix/f588bda19d3736ed425a109c378b2b23 to your computer and use it in GitHub Desktop.
Save kaiix/f588bda19d3736ed425a109c378b2b23 to your computer and use it in GitHub Desktop.
__kubectl_init_completion()
{
COMPREPLY=()
_get_comp_words_by_ref "$@" cur prev words cword
}
__kubectl_get_pod()
{
if declare -F _init_completion >/dev/null 2>&1; then
_init_completion -s || return
else
__kubectl_init_completion -n "=" || return
fi
local template
template="{{ range .items }}{{ .metadata.name }} {{ end }}"
local kubectl_out
if kubectl_out=$(kubectl get pod -o template --template="${template}" 2>/dev/null); then
COMPREPLY=( $( compgen -W "${kubectl_out[*]}" -- "$cur" ) )
fi
}
kenter()
{
kubectl exec -it $1 bash
}
complete -o default -o nospace -F __kubectl_get_pod kenter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment