Skip to content

zsh completions: nested groups emit multi-word names that fail to parse #72

Description

@hlship

Summary

completions emits nested group names as the joined :command-path (e.g. k8s pods, mcp nrepl) instead of the single next path segment (pods, nrepl). Those tokens are written unquoted into a zsh case arm, which is a parse error, so the generated script does not load.

Reproduced with ladder-cli 0.4.0 (ldr completions).

Cause

In extract-command, leaf commands use command-name, but groups without :fn set :name from the full path:

{:name (->> command-map
            :command-path
            (string/join " "))
 ...}

group.tpl then interpolates that into both _values candidates and case $line[1]. $line[1] is only the next word (e.g. pods after ldr k8s), not k8s pods.

There is already a ;; TODO: Support messy group/command combos in that function. The existing subgroup-completion test only nests one extra segment whose path is a single word (subgroup), so it does not catch this.

Generated (broken)

_ldr_k8s() {
  ...
       _values "ldr k8s subcommands"  \
         "auth[Obtain credentials for an environment]"  \
         "demo-image[Runs an image in a throw-away node]"  \
         "k8s pods[Managed Kubernetes pods]"
  ...
       case $line[1] in
         auth) _ldr_k8s_auth ;;
         demo-image) _ldr_k8s_demo_image ;;
         k8s pods) _ldr_k8s_pods ;;
       esac
}

Same pattern for mcp nrepl.

Expected

Use the group’s own command name (pods, nrepl) in _values and in case:

         "pods[Managed Kubernetes pods]"
         ...
         pods) _ldr_k8s_pods ;;

zsh -n on the generated file should succeed, and compinit should define _ldr_k8s, _ldr_mcp, and the rest of the nested functions.

Also observed (same generator)

  • #compdef _ldr ldr binds a fake command _ldr. Usual form is #compdef ldr (top-level.tpl).
  • When the tool has :version, -V/--version is added in dispatch via version-option but print-tool only concatenates extra-options and impl/default-tool-options, so version is omitted from completions.

Check

zsh -n path/to/_tool

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions