Skip to content
Permalink
Browse files

Add zsh completion for kubectx subcommand (-d) (#178)

- Add basic completion for subcommand -d.
  Note: Kubectx will suggest all available contexts.

- References:
  - http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-System
  - https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org
  • Loading branch information...
hpedrorodrigues authored and ahmetb committed Oct 24, 2019
1 parent 00a1e12 commit 9645e5c62c8b717dbccb8181b57af92f1b7b4081
Showing with 9 additions and 3 deletions.
  1. +9 −3 completion/kubectx.zsh
@@ -2,11 +2,17 @@

local KUBECTX="${HOME}/.kube/kubectx"
PREV=""

local all_contexts="$(kubectl config get-contexts --output='name')"
if [ -f "$KUBECTX" ]; then
# show '-' only if there's a saved previous context
local PREV=$(cat "${KUBECTX}")
_arguments "1: :(-
$(kubectl config get-contexts --output='name'))"

_arguments \
"-d:*: :(${all_contexts})" \
"(- *): :(- ${all_contexts})"
else
_arguments "1: :($(kubectl config get-contexts --output='name'))"
_arguments \
"-d:*: :(${all_contexts})" \
"(- *): :(${all_contexts})"
fi

0 comments on commit 9645e5c

Please sign in to comment.
You can’t perform that action at this time.