From 5933a7bbf8e5571738e6d95b0bd1650ac19e2036 Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Wed, 26 Apr 2017 09:34:35 -0700 Subject: [PATCH] Add zsh completion script (finally) Signed-off-by: Ahmet Alp Balkan --- Formula/kubectx.rb | 12 +++--------- completion/kubectx.zsh | 12 ++++++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 completion/kubectx.zsh diff --git a/Formula/kubectx.rb b/Formula/kubectx.rb index c1e8b70c..fe8ee64a 100644 --- a/Formula/kubectx.rb +++ b/Formula/kubectx.rb @@ -1,21 +1,15 @@ class Kubectx < Formula desc "Tool that can switch between kubectl contexts easily and create aliases" homepage "https://github.com/ahmetb/kubectx" - url "https://github.com/ahmetb/kubectx/archive/v0.1.tar.gz" - sha256 "841817f928af25061b1b6794400394c3e6e807e8a1c48c179f1fd8bdd553ca79" + url "https://github.com/ahmetb/kubectx/archive/v0.2.0.tar.gz" + sha256 "9fb6557416e4be3ef7e9701527f89fa73a1a0545a3cafbe6bed7527061c6cfb7" bottle :unneeded def install bin.install "kubectx" bash_completion.install "completion/kubectx.bash" => "kubectx" - end - - def caveats; <<-EOS.undent - To install zsh completion, add this to your .zshrc: - - [ -f /usr/local/etc/bash_completion.d/kubectx ] && source /usr/local/etc/bash_completion.d/kubectx - EOS + zsh_completion.install "completion/kubectx.zsh" => "_kubectx" end test do diff --git a/completion/kubectx.zsh b/completion/kubectx.zsh new file mode 100644 index 00000000..ada6dde5 --- /dev/null +++ b/completion/kubectx.zsh @@ -0,0 +1,12 @@ +#compdef kubectx + +KUBECTX="${HOME}/.kube/kubectx" +PREV="" +if [ -f "$KUBECTX" ]; then + # show '-' only if there's a saved previous context + PREV=$(cat "${KUBECTX}") + _arguments "1: :((-\:Back\ to\ ${PREV} \ + $(kubectl config get-contexts | awk '{print $2}' | tail -n +2)))" +else + _arguments "1: :($(kubectl config get-contexts | awk '{print $2}' | tail -n +2))" +fi