<p>k8s kubectl autocomplete is great, until you want to run a command for multiple things.</p>
<p>For example, I want to delete 2 pods, I can run:</p>
<p><code>k delete pod foo-12345 bar-67890</code></p>
<p>But I can only autocomplete with foo. What about bar&lt;tab&gt;?</p>

Spanky
<p>It is in the best case a partial workaround. After a few test, I can say that your goal can be achieved, but it have some cons. There might be a 3rd party solution but I am not aware of any.</p>
<p><strong>bash-completion</strong></p>
<p>'bash-completion' package is required for making kubectl shell completion work as expected. You can install it using <code>apt-get install bash-completionmo</code>. More information can be found in Kubernetes Documentation <a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/#optional-kubectl-configurations" rel="nofollow noreferrer">Optional kubectl configurations</a>.</p>
<p><strong>Debugging</strong></p>
<p><a href="https://iridakos.com/programming/2018/03/01/bash-programmable-completion-tutorial" rel="nofollow noreferrer">Bash-completion</a> has it's own syntax and functions. For debugging purpose you can run <code>export BASH_COMP_DEBUG_FILE=$HOME/compdebug.txt</code>. It will create <code>compdebug</code> text file and send all debug output from <code>kubectl shell</code> completion functions to it. Example output below:</p>
<pre><code>__kubectl_parse_get: get completion by kubectl get  -o template --template=&quot;{{ range .items  }}{{ .metadata.name }} {{ end }}&quot; &quot;first-deployment-85b75bf4f9-mn8zh&quot;
__kubectl_handle_word: c is 0 words[c] is kubectl
__kubectl_handle_command: c is 0 words[c] is kubectl
__kubectl_handle_command: looking for _kubectl_root_command
__kubectl_handle_word: c is 1 words[c] is get
__kubectl_handle_command: c is 1 words[c] is get
__kubectl_handle_command: looking for _kubectl_get
__kubectl_handle_word: c is 2 words[c] is pod
__kubectl_handle_noun: c is 2 words[c] is pod
__kubectl_handle_reply
__kubectl_parse_get: get completion by kubectl get  -o template --template=&quot;{{ range .items  }}{{ .metadata.name }} {{ end }}&quot; &quot;pod&quot;
</code></pre>
<p><strong>How it works</strong></p>
<p><code>kubectl</code> doesn't complete more than one object, because it's autocomplete function runs sub-request <code>kubectl get argN</code>  to get list of objects, and <code>argN</code> is the previous arguments of the existing command line. When you use it first time, it takes arguments from <code>kubectl command pod-&gt;argN</code> and run <code>kubectl get pod</code>. The second time it takes arguments from <code>kubectl command pod podname1-&gt;argN</code>, so the sub-request looks like <code>kubectl get podname1</code> instead of <code>kubectl get pod</code> which cause en error and empty output instead of list of the objects.</p>
<p><strong>Test Scenario</strong></p>
<p>To achieve this script you can use command <code>kubectl completion bash &gt; k8scompletion.sh</code>.</p>
<p>It's good to create second completion script that you can rollback to default settings - <code>kubectl completion bash &gt; k8scompletion-copy.sh</code>.</p>
<pre><code>$ vi k8scompletion.sh
</code></pre>
<p>In function <code>__kubectl_get_resource()</code> I've edited <code>__kubectl_parse_get &quot;${nouns[${#nouns[@]} -1]}&quot;</code> to <code>__kubectl_parse_get &quot;${nouns[0]}&quot;</code></p>
<pre><code>__kubectl_get_resource()
{
    if [[ ${#nouns[@]} -eq 0 ]]; then
      local kubectl_out
      if kubectl_out=$(__kubectl_debug_out &quot;kubectl api-resources $(__kubectl_override_flags) -o name --cached --request-timeout=5s --verbs=get&quot;); then
          COMPREPLY=( $( compgen -W &quot;${kubectl_out[*]}&quot; -- &quot;$cur&quot; ) )
          return 0
      fi
      return 1
    fi
    __kubectl_parse_get &quot;${nouns[0]}&quot;
}
</code></pre>
<p><strong>Script adjustment overview</strong></p>
<p>Adjusted script allows you to complete kubernetes resources and all objects from this resource. The following workaround is enough for demonstration and solving the mentioned in the question problem, but can cause some side effects, so please pay attention to the results you get.</p>
<p><strong>Side Note</strong></p>
<p>Shell completion script varies from one <code>kubectl</code> version to another, thus it is hard to create universal patch.</p>
<p><strong>Test Output</strong></p>
<pre><code>$ kubectl delete &lt;TAB&gt;
apiservices.apiregistration.k8s.io                            nodes.metrics.k8s.io
backendconfigs.cloud.google.com                               persistentvolumeclaims
certificatesigningrequests.certificates.k8s.io                persistentvolumes
clusterrolebindings.rbac.authorization.k8s.io                 poddisruptionbudgets.policy
clusterroles.rbac.authorization.k8s.io                        pods
componentstatuses                                             podsecuritypolicies.policy
configmaps                                                    pods.metrics.k8s.io
controllerrevisions.apps                                      podtemplates
cronjobs.batch                                                priorityclasses.scheduling.k8s.io
csidrivers.storage.k8s.io                                     replicasets.apps
... and few others

$ kubectl delete pod&lt;TAB&gt;
poddisruptionbudgets.policy  pods                         podsecuritypolicies.policy   pods.metrics.k8s.io          podtemplates

$ kubectl delete pod &lt;TAB&gt;&lt;TAB&gt;
httpd-deploy-1-6c4b998b99-jk876  httpd-deploy-6867dfd79c-tr648    nginx2                           nginx-deploy-2-94985d7bd-bdb4d
httpd-deploy-2-64dc95c468-s7vt2  nginx                            nginx-deploy-1-5494687955-sm5lh  nginx-deploy-85df977897-44lcn

$ kubectl get pod nginx&lt;TAB&gt;
nginx                            nginx2                           nginx-deploy-1-5494687955-sm5lh  nginx-deploy-2-94985d7bd-bdb4d   nginx-deploy-85df977897-44lcn

$ kubectl get pod nginx-deploy-&lt;TAB&gt;
nginx-deploy-1-5494687955-sm5lh  nginx-deploy-2-94985d7bd-bdb4d   nginx-deploy-85df977897-44lcn

$ kubectl get pod nginx-deploy-1&lt;TAB&gt;
###It autocomplete below after clicking on tab to nginx-deploy-1-5494687955-sm5lh

$ kubectl get pod nginx-deploy-1-5494687955-sm5lh &lt;TAB&gt;
httpd-deploy-1-6c4b998b99-jk876  httpd-deploy-6867dfd79c-tr648    nginx2                           nginx-deploy-2-94985d7bd-bdb4d
httpd-deploy-2-64dc95c468-s7vt2  nginx                            nginx-deploy-1-5494687955-sm5lh  nginx-deploy-85df977897-44lcn

$ kubectl delete pod nginx-deploy-1-5494687955-sm5lh nginx&lt;TAB&gt;
nginx                            nginx2                           nginx-deploy-1-5494687955-29vqs  nginx-deploy-2-94985d7bd-bdb4d   nginx-deploy-85df977897-44lcn
$ kubectl delete pod nginx-deploy-1-5494687955-sm5lh nginx2 &lt;TAB&gt;
httpd-deploy-1-6c4b998b99-jk876  httpd-deploy-6867dfd79c-tr648    nginx2                           nginx-deploy-2-94985d7bd-bdb4d
httpd-deploy-2-64dc95c468-s7vt2  nginx                            nginx-deploy-1-5494687955-29vqs  nginx-deploy-85df977897-44lcn
$ kubectl delete pod nginx-deploy-1-5494687955-sm5lh nginx2
</code></pre>
<p><strong>Rollback changes</strong></p>
<p>To apply this specific completion script, you have to use <code>source</code> command - <code>source k8scompletion.sh</code> or <code>source k8scompletion-copy.sh</code>.</p>
