title: How do I autocomplete nested, multi-level subcommands?
body: <p>I am trying to develop an autocomplete or tab-complete feature for my own set of commands.</p>
  
  <p>For example, assume foo is my binary:                                                 </p>
  
  <pre><code>CLI&gt;&gt; foo [TAB] [TAB]
  </code></pre>
  
  <p>It should show the main commands <code>configure</code> and <code>show</code>.</p>
  
  <p>Then if I select <code>configure</code>, it should show the subcommands <code>CM</code>, <code>DSP</code> and <code>NPU</code>:</p>
  
  <pre><code>CLI&gt;&gt; foo configure [TAB] [TAB]
  DSP NPU CM`
  </code></pre>
  
  <p>
                                                                                                  I only know how to tab-complete and display for the first level - how can I get the second level as well?</p>
  
  <p>I will place this in <code>/etc/completion.d</code>.</p>
  
  <p>My Code:     </p>
  
  <pre><code>_foo()
  {
      local cur prev opts
      COMPREPLY=()
      cur="${COMP_WORDS[COMP_CWORD]}"
      prev="${COMP_WORDS[COMP_CWORD-1]}"
      words=("${COMP_WORDS[@]}")
      cword=$COMP_CWORD
      opts="configure show"
  }
  </code></pre>
  
  <p>I'm stuck as how to add sub commands <code>CM</code> <code>DSP</code> <code>NPU</code> under <code>configure</code>.</p>