Skip to content

Expand zsh compdef patterns - #311

Merged
rsteube merged 3 commits into
carapace-sh:masterfrom
ahmadmustafaanis:bounty/zsh-compdef-patterns
Jul 11, 2026
Merged

Expand zsh compdef patterns#311
rsteube merged 3 commits into
carapace-sh:masterfrom
ahmadmustafaanis:bounty/zsh-compdef-patterns

Conversation

@ahmadmustafaanis

@ahmadmustafaanis ahmadmustafaanis commented May 12, 2026

Copy link
Copy Markdown
Contributor

Closes #261.

This updates zsh bridge command discovery so #compdef pattern entries are expanded against commands available in PATH instead of being discarded. Literal command entries still pass through the existing filters.

Changes:

  • enable zsh extended glob matching in zsh.sh
  • stop dropping compdef tokens that contain pattern metacharacters
  • expand pattern tokens with ${(M)${(k)commands}:#${~compdef}} and print matching command names

Validation:

  • PATH=/tmp/codex-go-toolchain/go/bin:$PATH go test ./...
  • PATH=/tmp/codex-go-toolchain/go/bin:$PATH go test ./cmd/...
  • PATH=/tmp/codex-go-toolchain/go/bin:$PATH go build ./cmd/carapace-bridge
  • git diff --check
  • manually ran pkg/bridges/zsh.sh with a locally extracted zsh package, a fake fpath containing #compdef (ruby|[ei]rb)[0-9.]# python[0-9.]# plain ..., and fake PATH commands; it emitted matching commands such as ruby, ruby3.2, erb, erb3, irb2, python3, and plain while filtering special/private entries.

ahmadmustafaanis and others added 3 commits May 13, 2026 02:46
… the glob loop

Lines like "#compdef -value-,DISPLAY,-default-" were reduced to a bare
"#compdef" by the sed option-stripping step. This reached the while
loop, matched the glob-character check, and caused an invalid pattern
error that aborted the entire loop, dropping all subsequent entries.
Filter these bare #compdef strings before the loop so glob expansion
runs to completion.

Assisted-by: Crush:glm-5.2
A bare #compdef was one bad pattern that aborted the while loop, but
malformed globs like unmatched parens or brackets from other zsh
completion packages could cause the same failure. Running the expansion
in a subshell with stderr suppressed ensures any bad pattern only
skips that single entry instead of aborting the entire loop.

Assisted-by: Crush:glm-5.2
@rsteube
rsteube merged commit 70a0817 into carapace-sh:master Jul 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zsh: support compdef patterns

3 participants