diff --git a/README.md b/README.md index d4efa02..bfb1df7 100644 --- a/README.md +++ b/README.md @@ -34,10 +34,10 @@ sudo mv ./kubectl-use /usr/local/bin/kubectl-use ``` ## Autocompletion -Add to your `.zshrc` or `.bashrc` file: +Currently krew does not support for installing completion, thus only curl method is available: ```bash -if command -V kubectl-use >/dev/null; then - source <(kubectl-use -completion) -fi +curl -LO https://github.com/kvaps/kubectl-use/raw/master/kubectl_complete-use +chmod +x ./kubectl_complete-use +sudo mv ./kubectl_complete-use /usr/local/bin/kubectl_complete-use ``` diff --git a/kubectl-use b/kubectl-use index 2aab55f..70574df 100755 --- a/kubectl-use +++ b/kubectl-use @@ -2,29 +2,7 @@ set -e case $1 in --completion) - cat <<\EOT -_kubectl_use() { - local cur prev opts - case "${COMP_LINE}" in - kubectl\ use\ * | kubectl-use\ *) - kubectl config get-contexts -o name - kubectl get ns -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' - return - ;; - esac - if command -v __start_kubectl >/dev/null; then - __start_kubectl - fi -} -complete -F _kubectl_use kubectl kubectl-use -EOT - exit 0 - ;; -* | "") - echo - echo " Completion:" - echo " source <(kubectl use -completion)" echo echo " Usage:" echo " kubectl use " diff --git a/kubectl_complete-use b/kubectl_complete-use new file mode 100755 index 0000000..0c422e7 --- /dev/null +++ b/kubectl_complete-use @@ -0,0 +1,11 @@ +#!/bin/sh +if [ "$#" -le 1 ]; then + if kubectl config get-contexts "$1" >/dev/null 2>&1; then + kubectl get namespaces --context "$1" -o custom-columns=NAME:.metadata.name --no-headers + else + (kubectl config get-contexts -o=name; kubectl get namespaces -o custom-columns=NAME:.metadata.name --no-headers) | grep "$1" + fi +fi +if [ "$#" -eq 2 ]; then + kubectl get namespaces --context "$1" -o custom-columns=NAME:.metadata.name --no-headers | grep "$2" +fi