Last active
August 29, 2015 14:20
-
-
Save eparis/4f70d833f556cb09d602 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/contrib/completions/bash/kubectl b/contrib/completions/bash/kubectl | |
index 639d768..5f546db 100644 | |
--- a/contrib/completions/bash/kubectl | |
+++ b/contrib/completions/bash/kubectl | |
@@ -157,14 +157,13 @@ __handle_word() | |
} | |
# call kubectl get $1, | |
-# use the first column in compgen | |
-# we could use templates, but then would need a template per resource | |
__kubectl_parse_get() | |
{ | |
- local kubectl_output out | |
- if kubectl_output=$(kubectl get --no-headers "$1" 2>/dev/null); then | |
- out=($(echo "${kubectl_output}" | awk '{print $1}')) | |
- COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) ) | |
+ local template | |
+ template="{{ range .items }}{{ .metadata.name }} {{ end }}" | |
+ local kubectl_out | |
+ if kubectl_out=$(kubectl get -o template --template="${template}" "$1" 2>/dev/null); then | |
+ COMPREPLY=( $( compgen -W "${kubectl_out[*]}" -- "$cur" ) ) | |
fi | |
} | |
@@ -180,7 +179,7 @@ __kubectl_get_resource() | |
__kubectl_get_containers() | |
{ | |
local template | |
- template="{{ range .desiredState.manifest.containers }}{{ .name }} {{ end }}" | |
+ template="{{ range .spec.containers }}{{ .name }} {{ end }}" | |
__debug "${FUNCNAME} nouns are ${nouns[*]}" | |
local len="${#nouns[@]}" | |
diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go | |
index e829504..c251f60 100644 | |
--- a/pkg/kubectl/cmd/cmd.go | |
+++ b/pkg/kubectl/cmd/cmd.go | |
@@ -28,14 +28,13 @@ import ( | |
const ( | |
bash_completion_func = `# call kubectl get $1, | |
-# use the first column in compgen | |
-# we could use templates, but then would need a template per resource | |
__kubectl_parse_get() | |
{ | |
- local kubectl_output out | |
- if kubectl_output=$(kubectl get --no-headers "$1" 2>/dev/null); then | |
- out=($(echo "${kubectl_output}" | awk '{print $1}')) | |
- COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) ) | |
+ local template | |
+ template="{{ range .items }}{{ .metadata.name }} {{ end }}" | |
+ local kubectl_out | |
+ if kubectl_out=$(kubectl get -o template --template="${template}" "$1" 2>/dev/null); then | |
+ COMPREPLY=( $( compgen -W "${kubectl_out[*]}" -- "$cur" ) ) | |
fi | |
} | |
@@ -51,7 +50,7 @@ __kubectl_get_resource() | |
__kubectl_get_containers() | |
{ | |
local template | |
- template="{{ range .desiredState.manifest.containers }}{{ .name }} {{ end }}" | |
+ template="{{ range .spec.containers }}{{ .name }} {{ end }}" | |
__debug "${FUNCNAME} nouns are ${nouns[*]}" | |
local len="${#nouns[@]}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment