Add zsh support to completion script#1559
Open
gnodet wants to merge 1 commit into
Open
Conversation
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>
This was referenced Mar 17, 2026
|
What I tested on zsh: $ mvnd [TAB]
# resulted in:
$ mvnd
clean generate-sources install post-integration-test pre-site process-sources site validate
compile generate-test-resources integration-test post-site prepare-package process-test-classes site-deploy verify
deploy generate-test-sources package pre-clean process-classes process-test-resources test
generate-resources initialize post-clean pre-integration-test process-resources process-test-sources test-compile $ mvnd cl [TAB]
# resulted in:
$ mvnd clean$ mvnd clean pa [TAB]
# resulted in:
$ mvnd clean package$ mvnd -pl m
# correctly gave me a list with all sub-modules$ mvn -P [TAB][TAB]
# resulted in:
-1 -B -C -D -N -P -T -U -V -X -am -amd -c -cpu -e -emp -ep -f -fae -ff -fn -gs -h -l -npr -npu -nsu -o -pl -q -rf -s -t -up -v |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mvnd-bash-completion.bashscript (auto-detects shell type)zshas valid--completionargument inCompletion.javaSupersedes #1514 by consolidating the zsh compatibility into the single existing script rather than adding a separate file. This avoids duplication and maintenance burden.
Approach
The script auto-detects bash vs zsh and adapts three shell-specific behaviors:
function_exists: usestypeset -f(zsh) vsdeclare -F(bash)typeset +(zsh) vscompgen -v(bash)${(P)var}(zsh) vs${!var}(bash)For zsh,
bashcompinitis loaded to provide bash-style completion builtins (complete,compgen,COMPREPLY). No global shell options (setopt) are modified.Credit
Based on the approach from #1514 by @janweinschenker.
Test plan
CompletionGeneratorTestsucceeds🤖 Generated with Claude Code