Skip to content

Refine bash completion option handling and context awareness#3773

Open
PeterDaveHello wants to merge 1 commit intonvm-sh:masterfrom
PeterDaveHello:improve/bash-completion-options
Open

Refine bash completion option handling and context awareness#3773
PeterDaveHello wants to merge 1 commit intonvm-sh:masterfrom
PeterDaveHello:improve/bash-completion-options

Conversation

@PeterDaveHello
Copy link
Collaborator

Make option suggestions context-aware by subcommand and argument position to avoid invalid combinations.
Avoid stale or duplicate suggestions (including value flags and glob-like aliases) while preserving current-word completion.
Align option lists with nvm --help and observed CLI behavior for run/exec/ls/uninstall.

GitHub Copilot PR Summary:

This pull request significantly improves the Bash completion logic for the nvm command, making completions more context-aware and robust. The changes refactor how options and arguments are parsed, provide more accurate suggestions based on subcommands and flags, and handle edge cases for specific commands.

Improvements to Bash completion logic:

  • Enhanced the __nvm_generate_completion function to filter out options that have already been used in the command line, preventing duplicate suggestions.
  • Refactored the __nvm_options function to accurately determine the current subcommand and argument state, enabling context-sensitive option suggestions for each subcommand and handling special cases like install and ls.

Context-aware completions for subcommands:

  • Updated the main __nvm completion function to parse the current subcommand and argument count, providing relevant completions for subcommands like use, run, exec, ls, list, uninstall, alias, and unalias, and handling special flags such as --lts and --no-alias.
  • Improved handling of installed node versions and aliases for completions, including error suppression for nvm_ls.

These changes make the tab-completion experience for nvm users more accurate and user-friendly by only suggesting relevant options and arguments based on the current command context.

Make option suggestions context-aware by subcommand and argument
position to avoid invalid combinations.
Avoid stale or duplicate suggestions (including value flags and
glob-like aliases) while preserving current-word completion.
Align option lists with nvm --help and observed CLI behavior for
run/exec/ls/uninstall.
@dosubot
Copy link

dosubot bot commented Feb 1, 2026

Related Documentation

No published documentation to review for changes on this repository.

Write your first living document

How did I do? Any feedback?  Join Discord

@caroguillermo717-png

This comment was marked as spam.

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.

2 participants