Multi Level Bash Completion Multi Level Bash Completion bash bash

Multi Level Bash Completion


Thanks to mkb's comment i looked into the p4-example, which was - unlike the Git example ;) - simple enough for me to adapt it to my case. Here is the working version which does exactly what i asked for:

have pbt &&_pbt_complete(){  local cur prev  COMPREPLY=()  cur=${COMP_WORDS[COMP_CWORD]}  prev=${COMP_WORDS[COMP_CWORD-1]}  if [ $COMP_CWORD -eq 1 ]; then    COMPREPLY=( $(compgen -W "asadmin deploy" -- $cur) )  elif [ $COMP_CWORD -eq 2 ]; then    case "$prev" in      "asadmin")        COMPREPLY=( $(compgen -W "start-domain stop-domain" -- $cur) )        ;;      "deploy")        COMPREPLY=( $(compgen -W "all current" -- $cur) )        ;;      *)        ;;    esac  fi  return 0} &&complete -F _pbt_complete pbt


You may want to look at how the completion for git is done, as an example. (This takes 2257 lines of function definitions and additional 14 variables in my bash setup.)