Skip to content

Backport: Add zsh support to completion script - #1562

Open
gnodet wants to merge 1 commit into
mvnd-1.xfrom
backport/zsh-completion-1.x
Open

Backport: Add zsh support to completion script#1562
gnodet wants to merge 1 commit into
mvnd-1.xfrom
backport/zsh-completion-1.x

Conversation

@gnodet

@gnodet gnodet commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Backport of #1559 to mvnd-1.x.

  • Auto-detect shell type (bash vs zsh) and set up bashcompinit for zsh compatibility
  • Replace bash-specific builtins (declare -F, compgen -v, ${!var}) with shell-conditional equivalents (typeset -f, typeset +, ${(P)var})
  • Accept both bash and zsh as --completion values
  • Update README to document zsh support

Cherry-picked cleanly from master commit 7f7db5e.

🤖 Generated with Claude Code

Make the existing bash completion script work in both bash and zsh
by auto-detecting the shell and adapting behavior accordingly:

- Add shell detection via $ZSH_VERSION / $BASH_VERSION
- Load bashcompinit in zsh for bash-style completion compatibility
- Use typeset instead of declare/compgen for zsh
- Use ${(P)var} instead of ${!var} for indirect expansion in zsh
- Accept 'zsh' as valid --completion argument in Completion.java
- Update README.adoc with zsh instructions

Based on the approach from PR #1514 by janweinschenker, consolidated
into the single existing script to avoid duplication.

Co-Authored-By: Jan Weinschenker <janweinschenker@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shell script changes are technically correct — typeset -f for function checks, typeset + for variable enumeration, ${(P)var} for indirect expansion, and bashcompinit are all standard zsh idioms. The single-script approach with runtime detection is clean.

Two observations:

  1. Backport ahead of original (medium): This PR is described as a backport of #1559, but PR #1559 is still open on master with zero reviews. The commit 7f7db5e referenced as "master commit" actually lives on the unified-bash-zsh-completion feature branch, not master. Merging the backport before the original is reviewed risks divergence if the original gets modified during review. Consider merging #1559 on master first, then cherry-picking to mvnd-1.x.

  2. Missing zsh test (low): The existing completionBash() test only exercises --completion bash. Since Completion.java now accepts zsh, a parallel completionZsh() test calling client.execute(output, "--completion", "zsh") would guard against regressions in argument validation.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of gnodet

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-structured backport adding zsh completion support. The auto-detection approach using bashcompinit is sound and CI passes.

Two minor items to consider:

  1. Javadoc inconsistency in Environment.java (medium): The Javadoc for the COMPLETION constant (line 51) still reads "Only --completion bash is supported at this time", but this PR now accepts both bash and zsh. The README correctly removes the bash-only language, but Environment.java was not updated. This could mislead future maintainers.

  2. Missing zsh integration test (low): CompletionNativeIT.java only tests --completion bash. Since both bash and zsh resolve to the same file and produce identical output, a completionZsh() test would mainly guard the string validation gate in Completion.java — nice to have but low priority.

Also note: PR #1559 (the original change on master) is still open. This makes this an unusual forward-backport of an unmerged change — you may want to merge #1559 first or note in the description that parallel merging is intentional.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of gnodet

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.

1 participant