diff --git a/clap_complete/src/shells/zsh.rs b/clap_complete/src/shells/zsh.rs index e9b8fdc695a..a41eb8856e2 100644 --- a/clap_complete/src/shells/zsh.rs +++ b/clap_complete/src/shells/zsh.rs @@ -43,7 +43,11 @@ _{name}() {{ {subcommand_details} -_{name} \"$@\" +if [ \"$funcstack[1]\" = \"_{name}\" ]; then + _{name} \"$@\" +else + compdef _{name} {name} +fi ", name = bin_name, initial_args = get_args_of(cmd, None), diff --git a/clap_complete/tests/snapshots/aliases.zsh b/clap_complete/tests/snapshots/aliases.zsh index 403bbfe864d..63764e56191 100644 --- a/clap_complete/tests/snapshots/aliases.zsh +++ b/clap_complete/tests/snapshots/aliases.zsh @@ -37,4 +37,8 @@ _my-app_commands() { _describe -t commands 'my-app commands' commands "$@" } -_my-app "$@" +if [ "$funcstack[1]" = "_my-app" ]; then + _my-app "$@" +else + compdef _my-app my-app +fi diff --git a/clap_complete/tests/snapshots/basic.zsh b/clap_complete/tests/snapshots/basic.zsh index 217ed938643..408bb7e4b8d 100644 --- a/clap_complete/tests/snapshots/basic.zsh +++ b/clap_complete/tests/snapshots/basic.zsh @@ -97,4 +97,8 @@ _my-app__test_commands() { _describe -t commands 'my-app test commands' commands "$@" } -_my-app "$@" +if [ "$funcstack[1]" = "_my-app" ]; then + _my-app "$@" +else + compdef _my-app my-app +fi diff --git a/clap_complete/tests/snapshots/feature_sample.zsh b/clap_complete/tests/snapshots/feature_sample.zsh index 3b4a7b64b53..72b85e11fff 100644 --- a/clap_complete/tests/snapshots/feature_sample.zsh +++ b/clap_complete/tests/snapshots/feature_sample.zsh @@ -104,4 +104,8 @@ _my-app__test_commands() { _describe -t commands 'my-app test commands' commands "$@" } -_my-app "$@" +if [ "$funcstack[1]" = "_my-app" ]; then + _my-app "$@" +else + compdef _my-app my-app +fi diff --git a/clap_complete/tests/snapshots/quoting.zsh b/clap_complete/tests/snapshots/quoting.zsh index 4afe4438a72..95ed7eb697d 100644 --- a/clap_complete/tests/snapshots/quoting.zsh +++ b/clap_complete/tests/snapshots/quoting.zsh @@ -211,4 +211,8 @@ _my-app__help__help_commands() { _describe -t commands 'my-app help help commands' commands "$@" } -_my-app "$@" +if [ "$funcstack[1]" = "_my-app" ]; then + _my-app "$@" +else + compdef _my-app my-app +fi diff --git a/clap_complete/tests/snapshots/special_commands.zsh b/clap_complete/tests/snapshots/special_commands.zsh index 42023be705c..67d04bdae4b 100644 --- a/clap_complete/tests/snapshots/special_commands.zsh +++ b/clap_complete/tests/snapshots/special_commands.zsh @@ -178,4 +178,8 @@ _my-app__test_commands() { _describe -t commands 'my-app test commands' commands "$@" } -_my-app "$@" +if [ "$funcstack[1]" = "_my-app" ]; then + _my-app "$@" +else + compdef _my-app my-app +fi diff --git a/clap_complete/tests/snapshots/sub_subcommands.zsh b/clap_complete/tests/snapshots/sub_subcommands.zsh index 7a14feb5559..720e72f1278 100644 --- a/clap_complete/tests/snapshots/sub_subcommands.zsh +++ b/clap_complete/tests/snapshots/sub_subcommands.zsh @@ -224,4 +224,8 @@ _my-app__test_commands() { _describe -t commands 'my-app test commands' commands "$@" } -_my-app "$@" +if [ "$funcstack[1]" = "_my-app" ]; then + _my-app "$@" +else + compdef _my-app my-app +fi diff --git a/clap_complete/tests/snapshots/two_multi_valued_arguments.zsh b/clap_complete/tests/snapshots/two_multi_valued_arguments.zsh index e0d49622b53..a20088ea2a0 100644 --- a/clap_complete/tests/snapshots/two_multi_valued_arguments.zsh +++ b/clap_complete/tests/snapshots/two_multi_valued_arguments.zsh @@ -27,4 +27,8 @@ _my-app_commands() { _describe -t commands 'my-app commands' commands "$@" } -_my-app "$@" +if [ "$funcstack[1]" = "_my-app" ]; then + _my-app "$@" +else + compdef _my-app my-app +fi diff --git a/clap_complete/tests/snapshots/value_hint.zsh b/clap_complete/tests/snapshots/value_hint.zsh index 15892dd7f08..c3a97f754b5 100644 --- a/clap_complete/tests/snapshots/value_hint.zsh +++ b/clap_complete/tests/snapshots/value_hint.zsh @@ -47,4 +47,8 @@ _my-app_commands() { _describe -t commands 'my-app commands' commands "$@" } -_my-app "$@" +if [ "$funcstack[1]" = "_my-app" ]; then + _my-app "$@" +else + compdef _my-app my-app +fi diff --git a/clap_complete/tests/snapshots/value_terminator.zsh b/clap_complete/tests/snapshots/value_terminator.zsh index 656d8ea182e..fe819420f82 100644 --- a/clap_complete/tests/snapshots/value_terminator.zsh +++ b/clap_complete/tests/snapshots/value_terminator.zsh @@ -27,4 +27,8 @@ _my-app_commands() { _describe -t commands 'my-app commands' commands "$@" } -_my-app "$@" +if [ "$funcstack[1]" = "_my-app" ]; then + _my-app "$@" +else + compdef _my-app my-app +fi