I have a command with a very structured input like
cmd --help cmd A -flagA1 X cmd A -flagA2 Y cmd B -flagB1 Z
Where X
,Y
,Z
are fixed values and depend on whether A
or B
is enabled.
Ideally, I'm trying to generate an autocomplete script for zsh to have the following behavior
cmd subA <tab> --> display X,Y cmd subA -<tab> --> display flagA1, flagA2
My current script look like this
#compdef _cmd _cmd () { typeset -A opt_args local state line curcontext="$curcontext" state_descr _arguments -C \ ': :->command' \ ': :->subcmd' \ && ret=0 case $state in (command) # local array variable local -a subcommands subcommands=( 'A:Do A' 'B:Do B' ) _describe -t commands 'subcommands' subcommands && ret=0 ;; (subcmd) case $line[1] in (A) _cmd_A_cmd ;; (B) ;; esac ;; esac } _cmd_A_cmd () { typeset -A opt_args local state line curcontext="$curcontext" state_descr _arguments -C \ ':: :->options' \ ': :->subcmd' \ && ret=0 case $state in (options) _arguments '-flagA1:the flag A1' \ '-flagA2:flag A2' ;; (subcmd) _values "A subcommand"\ 'X[X option]' \ 'Y[Y option]' ;; esac }
It works to get command A and B, and within A to get option X,Y, but I can't get the flags to work.
Any help appreciated.