diff --git a/completion/plugins/kubectl_complete-ctx b/completion/plugins/kubectl_complete-ctx new file mode 100755 index 0000000..fb9edea --- /dev/null +++ b/completion/plugins/kubectl_complete-ctx @@ -0,0 +1,28 @@ +#!/bin/bash + +__kubectl_debug() +{ + if [[ -n ${BASH_COMP_DEBUG_FILE:-} ]]; then + echo "$*" >> "${BASH_COMP_DEBUG_FILE}" + fi +} + +_kube_namespaces() +{ + local args lastArgs; + + args=("${@:1}") + __kubectl_debug "arguments list ${args[*]}" + len=${#args[@]} + __kubectl_debug "arguments len is $len" + if [[ $len -gt 0 ]]; then + lastArgs="${args[$((len-1))]}" + else + lastArgs="" + fi + __kubectl_debug "arguments last args on which completion will be done $lastArgs" + COMPREPLY=("$(compgen -W "$(kubectl config get-contexts -o name)" -- $lastArgs )"); +} + +_kube_namespaces "$@" +echo "${COMPREPLY[*]}" \ No newline at end of file diff --git a/completion/plugins/kubectl_complete-ns b/completion/plugins/kubectl_complete-ns new file mode 100755 index 0000000..5905eaa --- /dev/null +++ b/completion/plugins/kubectl_complete-ns @@ -0,0 +1,28 @@ +#!/bin/bash + +__kubectl_debug() +{ + if [[ -n ${BASH_COMP_DEBUG_FILE:-} ]]; then + echo "$*" >> "${BASH_COMP_DEBUG_FILE}" + fi +} + +_kube_namespaces() +{ + local args lastArgs; + + args=("${@:1}") + __kubectl_debug "arguments list ${args[*]}" + len=${#args[@]} + __kubectl_debug "arguments len is $len" + if [[ $len -gt 0 ]]; then + lastArgs="${args[$((len-1))]}" + else + lastArgs="" + fi + __kubectl_debug "arguments last args on which completion will be done $lastArgs" + COMPREPLY=("$(compgen -W "- $(kubectl get namespaces -o=jsonpath='{range .items[*].metadata.name}{@}{"\n"}{end}')" -- $lastArgs )"); +} + +_kube_namespaces "$@" +echo "${COMPREPLY[*]}" \ No newline at end of file