Skip to content

feat(cli): add shell completion support#974

Open
nekomoyi wants to merge 8 commits intovoidzero-dev:mainfrom
nekomoyi:feat/cli-completion
Open

feat(cli): add shell completion support#974
nekomoyi wants to merge 8 commits intovoidzero-dev:mainfrom
nekomoyi:feat/cli-completion

Conversation

@nekomoyi
Copy link
Contributor

@nekomoyi nekomoyi commented Mar 16, 2026

Summary

Implements shell completion for the vp CLI.

Changes

Completion scripts for bash, zsh, fish, and PowerShell are generated in ~/.vite-plus/completion/ when running vp env setup, and automatically sourced in the respective env files.

Fixes

Fixed mixed path separators in env files on Windows to use forward slashes consistently for $HOME-relative paths

# Before
__vp_bin="$HOME/.vite-plus\bin"
# After
__vp_bin="$HOME/.vite-plus/bin"

Increased stack size to 8MB to handle deep recursion in clap_complete::generate() which exceeds Windows' default stack size.

Closes #950

@netlify
Copy link

netlify bot commented Mar 16, 2026

Deploy Preview for viteplus-preview ready!

Name Link
🔨 Latest commit 55918b2
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/69bd176e428ff60008eab295
😎 Deploy Preview https://deploy-preview-974--viteplus-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@fengmk2 fengmk2 self-requested a review March 17, 2026 03:39
@nekomoyi
Copy link
Contributor Author

Looking into the CI failure.

@nekomoyi nekomoyi marked this pull request as draft March 17, 2026 07:22
@nekomoyi nekomoyi marked this pull request as ready for review March 17, 2026 08:32
Copy link
Member

@fengmk2 fengmk2 left a comment

Choose a reason for hiding this comment

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

@nekomoyi Thanks! I will merge after successful local verification.

@wtto00
Copy link

wtto00 commented Mar 19, 2026

There is a bug in the __vp_bin path configuration. Please see #1039.

@fengmk2
Copy link
Member

fengmk2 commented Mar 19, 2026

@nekomoyi can you rebase and fix conflicts?

…ive paths

Fix mixed path separators in env files on Windows
- Before: $HOME/.vite-plus\bin (mixed)
- After: $HOME/.vite-plus/bin (consistent)
Simplify completion generation with loop-based approach
…dows

- Increase stack size to 8MB on Windows
- Set RUST_MIN_STACK to 8MB in CI test jobs

Cargo test default (2MB) are insufficient for deep recursion in clap_complete::generate(). This causes stack overflow when generating shell completion scripts during tests.
@nekomoyi nekomoyi force-pushed the feat/cli-completion branch from 0d02ce0 to 9fb37ec Compare March 19, 2026 05:21
@fengmk2 fengmk2 self-assigned this Mar 19, 2026
@nekomoyi
Copy link
Contributor Author

nekomoyi commented Mar 19, 2026

There is a bug in the __vp_bin path configuration. Please see #1039.

The forward/backward slash path issue in __vp_bin has been addressed in this PR.

# .vite-plus/env
__vp_bin="$HOME/.vite-plus/bin"
# .vite-plus/env.ps1
$__vp_bin = "C:\Users\nekomoyi\.vite-plus\bin"

@fengmk2
Copy link
Member

fengmk2 commented Mar 19, 2026

@codex review

@fengmk2 fengmk2 linked an issue Mar 19, 2026 that may be closed by this pull request
4 tasks
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 444eabb7bd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +481 to +485
elif [ -n "$ZSH_VERSION" ] && type compdef >/dev/null 2>&1; then
# Zsh shell with completion support
__vp_completion="__VP_COMPLETION_ZSH__"
if [ -f "$__vp_completion" ]; then
. "$__vp_completion"

Choose a reason for hiding this comment

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

P2 Badge Defer zsh completion registration until compinit is ready

This only sources _vp when compdef is already defined. In many real .zshrc setups, ~/.vite-plus/env is sourced before compinit runs (for example, before oh-my-zsh.sh), and the zsh docs explicitly place compdef registration after compinit. In that ordering this branch no-ops and nothing retries later, so vp completion never becomes available even though setup succeeded.

Useful? React with 👍 / 👎.

Comment on lines +517 to +520
# Shell completion for fish
set -l __vp_completion "__VP_COMPLETION_FISH__"
if test -f "$__vp_completion"
source "$__vp_completion"

Choose a reason for hiding this comment

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

P2 Badge Avoid re-adding fish completions every time env.fish is sourced

env.fish now unconditionally re-sources the generated vp.fish script. Fish's complete builtin adds definitions on top of existing ones when called multiple times, and clap_complete's generated fish script does not clear prior entries first, so any common reload flow like source ~/.config/fish/config.fish or source ~/.vite-plus/env.fish will duplicate every vp completion item in the current session.

Useful? React with 👍 / 👎.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 444eabb7bd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +481 to +485
elif [ -n "$ZSH_VERSION" ] && type compdef >/dev/null 2>&1; then
# Zsh shell with completion support
__vp_completion="__VP_COMPLETION_ZSH__"
if [ -f "$__vp_completion" ]; then
. "$__vp_completion"

Choose a reason for hiding this comment

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

P2 Badge Defer zsh completion registration until compinit is ready

This only sources _vp when compdef is already defined. In many real .zshrc setups, ~/.vite-plus/env is sourced before compinit runs (for example, before oh-my-zsh.sh), and the zsh docs explicitly place compdef registration after compinit. In that ordering this branch no-ops and nothing retries later, so vp completion never becomes available even though setup succeeded.

Useful? React with 👍 / 👎.

Comment on lines +517 to +520
# Shell completion for fish
set -l __vp_completion "__VP_COMPLETION_FISH__"
if test -f "$__vp_completion"
source "$__vp_completion"

Choose a reason for hiding this comment

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

P2 Badge Avoid re-adding fish completions every time env.fish is sourced

env.fish now unconditionally re-sources the generated vp.fish script. Fish's complete builtin adds definitions on top of existing ones when called multiple times, and clap_complete's generated fish script does not clear prior entries first, so any common reload flow like source ~/.config/fish/config.fish or source ~/.vite-plus/env.fish will duplicate every vp completion item in the current session.

Useful? React with 👍 / 👎.

@fengmk2
Copy link
Member

fengmk2 commented Mar 19, 2026

@nekomoyi There is a problem with the automatic suggestions for subcommands, for example, vp build prompts thousands of possibilities.

vp build                                                                                                              
zsh: do you wish to see all 3976 possibilities (1999 lines)? 

@nekomoyi
Copy link
Contributor Author

@fengmk2 I tried to reproduce the problem on my side but couldn't replicate it. When I type vp build and press Tab to trigger completion, it only lists the files in the current directory.

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.

Add Git Bash (Windows) support to the CLI Shell completion support

3 participants