I've tried (and failed miserably) to write a bash completion script that can take arbitrarily deep autocompletion. I didn't make it past two :-\ despite reading multiple SO posts and some blogs and docs. For example, I can get to:
$ seuss tweedle beetle
but can't get to seuss tweedle beetle puddle
I don't even really need functions at the end of each complete, just the options themselves. I tried modifying scripts from the following posts but everything I did would break.
Nested bash autocompletion script
How do I autocomplete nested, multi-level subcommands?
Here's what I've tried:
_seuss()
{
local one two three four
one=${COMP_WORDS[COMP_CWORD]}
two=${COMP_WORDS[COMP_CWORD-1]}
three=${COMP_WORDS[COMP_CWORD-2]}
four=${COMP_WORDS[COMP_CWORD-3]}
case ${COMP_CWORD} in
1)
COMPREPLY=($(compgen -W "fox tweedle" -- ${one}))
;;
2)
case ${two} in
fox)
COMPREPLY=($(compgen -W "socks" -- ${one}))
case ${three} in
socks)
COMPREPLY=($(compgen -W "box clocks" -- ${one}))
;;
box)
COMPREPLY=($(compgen -W "knox" -- ${one}))
;;
esac
;;
tweedle)
COMPREPLY=($(compgen -W "beetle poodle" -- ${one}))
case ${three} in
beetle)
COMPREPLY=($(compgen -W "puddle battle" -- ${one}))
;;
poddle)
COMPREPLY=($(compgen -W "noodle" -- ${one}))
;;
esac
;;
esac
;;
*)
COMPREPLY=()
;;
esac
}
complete -F _seuss seuss
But this only results in:
$ seuss fox sox
I can't seem to get box clocks
.