diff --git a/src/completions/zsh.rs b/src/completions/zsh.rs index 3e9452d1..057e05fe 100644 --- a/src/completions/zsh.rs +++ b/src/completions/zsh.rs @@ -230,15 +230,18 @@ fn get_subcommands_of(p: &Parser) -> String { format!( "case $state in ({name}) - curcontext=\"${{curcontext%:*:*}}:{name_hyphen}-command-$words[1]:\" - case $line[1] in + words=($line[{pos}] \"${{words[@]}}\") + (( CURRENT += 1 )) + curcontext=\"${{curcontext%:*:*}}:{name_hyphen}-command-$line[{pos}]:\" + case $line[{pos}] in {subcommands} esac ;; esac", name = p.meta.name, name_hyphen = p.meta.bin_name.as_ref().unwrap().replace(" ", "-"), - subcommands = subcmds.join("\n") + subcommands = subcmds.join("\n"), + pos = p.positionals().len() + 1 ) } @@ -285,7 +288,7 @@ fn get_args_of(p: &Parser) -> String { String::new() }; let sc = if p.has_subcommands() { - format!("\"*:: :->{name}\" \\", name = p.meta.name) + format!("\"*::: :->{name}\" \\", name = p.meta.name) } else { String::new() }; diff --git a/tests/completions.rs b/tests/completions.rs index c90b91b8..fc343ee5 100644 --- a/tests/completions.rs +++ b/tests/completions.rs @@ -101,12 +101,14 @@ _myapp() { '--version[Prints version information]' \ "::file -- some input file:_files" \ ":: :_myapp_commands" \ -"*:: :->myapp" \ +"*::: :->myapp" \ && ret=0 case $state in (myapp) - curcontext="${curcontext%:*:*}:myapp-command-$words[1]:" - case $line[1] in + words=($line[2] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:myapp-command-$line[2]:" + case $line[2] in (test) _arguments -s -S -C \ '--case=[the case to test]' \ @@ -390,12 +392,14 @@ _my_app() { '--version[Prints version information]' \ "::file -- some input file:_files" \ ":: :_my_app_commands" \ -"*:: :->my_app" \ +"*::: :->my_app" \ && ret=0 case $state in (my_app) - curcontext="${curcontext%:*:*}:my_app-command-$words[1]:" - case $line[1] in + words=($line[2] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:my_app-command-$line[2]:" + case $line[2] in (test) _arguments -s -S -C \ '--case=[the case to test]' \