[Docs] nvm --help: list nvm use --delete-prefix

Completion offers what the help lists, so it offers the flag too.

Fixes #4013
This commit is contained in:
Srinivas Chippagiri authored and Jordan Harband committed 2026-11-29 20:39:32 -08:00
1 parent 43a65b3ac5
commit 2404c007fb
3 files changed
+57 -1

No files matched your search

+3 -1
View File
@@ -107,6 +107,7 @@ __nvm_parse_context() {
--no-alias) no_alias='' ;;
-s | -b) build_mode='' ;;
--save | -w) save='' ;;
--delete-prefix) delete_prefix='' ;;
--default | --alias=*) alias_target='' ;;
--reinstall-packages-from=* | --copy-packages-from=*) reinstall='' ;;
-*) ;;
@@ -131,7 +132,7 @@ __nvm_options() {
uninstall | use)
flags="${only}"
if (( arg_count == 0 )); then flags="${flags} ${lts_flags}"; fi
if [ "${subcommand}" = use ]; then flags="${flags} --silent ${save}"; fi
if [ "${subcommand}" = use ]; then flags="${flags} --silent ${save} ${delete_prefix}"; fi
;;
exec | run) flags="--silent ${lts_flags} ${only}" ;;
ls | list)
@@ -186,6 +187,7 @@ __nvm_candidates() {
local arg_count=0 end_options=0
local only='--only=' lts='--lts --lts=' no_alias='--no-alias'
local build_mode='-s -b' save='--save' alias_target='--alias= --default' reinstall='--reinstall-packages-from='
local delete_prefix='--delete-prefix'
local NVM_ONLY_SELECTED="${NVM_ONLY_SELECTED-}"
__nvm_parse_context || return 0
if (( ! end_options )); then
+1
View File
@@ -5416,6 +5416,7 @@ nvm() {
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
nvm_echo ' --only=<categories> Only select from these version categories (see above)'
nvm_echo ' --save Writes the specified version to .nvmrc.'
nvm_echo ' --delete-prefix Removes `prefix` and `globalconfig` from the user, global and builtin npmrc files instead of erroring'
nvm_echo ' nvm exec [current | <version>] [<command>] Run <command> on <version>. Uses .nvmrc if version is omitted; otherwise errors.'
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm exec`:'
nvm_echo ' --silent Silences stdout/stderr output'
@@ -0,0 +1,53 @@
#!/bin/sh
# shellcheck shell=bash
{ [ -n "${BASH_VERSION-}" ] && ! shopt -oq posix; } || exec bash "$0" "$@"
set -e
die() { printf '%s\n' "$*" >&2; exit 1; }
root="$(cd "$(dirname "$0")/../../.." && pwd)"
NVM_DIR="$(mktemp -d)"
export NVM_DIR
trap 'rm -rf "${NVM_DIR}"; [ -n "${finished-}" ]' EXIT
# shellcheck disable=SC1091
. "${root}/nvm.sh" --no-use
# shellcheck disable=SC1091
. "${root}/bash_completion"
complete_for() {
COMP_WORDS=("$@")
COMP_CWORD=$(( $# - 1 ))
COMPREPLY=(stale)
__nvm
}
offers() {
local reply
for reply in "${COMPREPLY[@]}"; do
[ "${reply}" = '--delete-prefix' ] && return 0
done
return 1
}
complete_for nvm use --de
[ "${COMPREPLY[*]}" = '--delete-prefix' ] || die "nvm use --de: got [${COMPREPLY[*]}]"
complete_for nvm use 22 --de
[ "${COMPREPLY[*]}" = '--delete-prefix' ] || die "nvm use 22 --de: got [${COMPREPLY[*]}]"
complete_for nvm use --silent -
offers || die "nvm use --silent -: --delete-prefix missing from [${COMPREPLY[*]}]"
complete_for nvm use --delete-prefix -
! offers || die 'offered --delete-prefix twice'
complete_for nvm use -- --de
! offers || die 'offered --delete-prefix after --'
for cmd in install uninstall exec run; do
complete_for nvm "${cmd}" --de
! offers || die "offered --delete-prefix to nvm ${cmd}"
done
finished=1