Skip to content

Commit 5c0725a

Browse files
committed
Merge pull request kubernetes#13089 from JanetKuo/kubectl-exec-bash-completion
Enable kubectl exec pod name bash completion
2 parents 08cddd8 + 46eb607 commit 5c0725a

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

contrib/completions/bash/kubectl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ __kubectl_get_resource()
181181
__kubectl_parse_get "${nouns[${#nouns[@]} -1]}"
182182
}
183183

184+
__kubectl_get_resource_pod()
185+
{
186+
__kubectl_parse_get "pod"
187+
}
188+
184189
# $1 is the name of the pod we want to get the list of containers inside
185190
__kubectl_get_containers()
186191
{
@@ -213,13 +218,17 @@ __kubectl_require_pod_and_container()
213218
__custom_func() {
214219
case ${last_command} in
215220
kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop)
216-
__kubectl_get_resource
221+
__kubectl_get_resource
222+
return
223+
;;
224+
kubectl_logs)
225+
__kubectl_require_pod_and_container
226+
return
227+
;;
228+
kubectl_exec)
229+
__kubectl_get_resource_pod
217230
return
218231
;;
219-
kubectl_logs)
220-
__kubectl_require_pod_and_container
221-
return
222-
;;
223232
*)
224233
;;
225234
esac

pkg/kubectl/cmd/cmd.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ __kubectl_get_resource()
4747
__kubectl_parse_get "${nouns[${#nouns[@]} -1]}"
4848
}
4949
50+
__kubectl_get_resource_pod()
51+
{
52+
__kubectl_parse_get "pod"
53+
}
54+
5055
# $1 is the name of the pod we want to get the list of containers inside
5156
__kubectl_get_containers()
5257
{
@@ -79,13 +84,17 @@ __kubectl_require_pod_and_container()
7984
__custom_func() {
8085
case ${last_command} in
8186
kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop)
82-
__kubectl_get_resource
87+
__kubectl_get_resource
88+
return
89+
;;
90+
kubectl_logs)
91+
__kubectl_require_pod_and_container
92+
return
93+
;;
94+
kubectl_exec)
95+
__kubectl_get_resource_pod
8396
return
8497
;;
85-
kubectl_logs)
86-
__kubectl_require_pod_and_container
87-
return
88-
;;
8998
*)
9099
;;
91100
esac

0 commit comments

Comments
 (0)