title: Bash nested autocomplete calling nested functions
body: <p>I'm attempting to build a generator for bash completion, but I need to be able to call 'nested' commands. Here is what I have so far. </p>
  
  <pre><code>#!bash
  
  _test()
  {
    local cur prev
  
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}
  
    case ${COMP_CWORD} in
      1)
        COMPREPLY=($(compgen -W "plain" -- ${cur}))
      ;;
      2)
        case ${prev} in
          plain)
            _plain
          ;;
          show)
            COMPREPLY=($(compgen -W "some other args" -- ${cur}))
          ;;
        esac
      ;;
      *)
        COMPREPLY=()
      ;;
    esac
  }
  
  _plain() {
    local cur prev
  
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}
  
  echo ${COMP_CWORD}
  echo $cur
  echo $prev
    case ${COMP_CWORD} in
      2)
        COMPREPLY=($(compgen -W "one two three" -- ${cur}))
      ;;
      3)
        case ${prev} in
          one)
            __one
          ;;
        esac
      ;;
      *)
        COMPREPLY=()
      ;;
    esac
  }
  
  __one() {
    echo "another"
  }
  
  complete -F _test test
  </code></pre>
  
  <p>including debug output. For some reason <code>COMP_CWORD</code>, <code>cur</code>, and <code>prev</code> do not get updated when calling down into the <code>__one</code> function. In what way can I accomplish a nested bash completion script like this?</p>