[Fix] install.sh: ignore commented-out profile source lines

`nvm_do_install` decided whether the profile already loads nvm, and its bash completion,
by grepping for `/nvm.sh` and `$NVM_DIR/bash_completion` anywhere in it,
so a commented-out line, the usual way to disable nvm, counted as present,
and reinstalling left the shell with no nvm.

Only count a line whose first non-blank character isn't `#`.

Fixes #1889.

Signed-off-by: Vaibhav Cheruvu <vaibhavsharma.c@gmail.com>
Co-authored-by: Vaibhav Cheruvu <vaibhavsharma.c@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
This commit is contained in:
Vaibhav CheruvuandJordan Harband authored and Jordan Harband committed 2026-11-03 13:21:38 -06:00
1 parent 7ab48a653b
commit db03e5e1c3
2 files changed
+65 -2

No files matched your search

+2 -2
View File
@@ -527,14 +527,14 @@ nvm_do_install() {
if nvm_profile_is_bash_or_zsh "${NVM_PROFILE-}"; then
BASH_OR_ZSH=true
fi
if ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then
if ! command grep -qc '^[[:space:]]*[^#[:space:]].*/nvm\.sh' "$NVM_PROFILE"; then
nvm_echo "=> Appending nvm source string to $NVM_PROFILE"
command printf '%b' "${SOURCE_STR}" >> "$NVM_PROFILE"
else
nvm_echo "=> nvm source string already in ${NVM_PROFILE}"
fi
# shellcheck disable=SC2016
if ${BASH_OR_ZSH} && ! command grep -qc '$NVM_DIR/bash_completion' "$NVM_PROFILE"; then
if ${BASH_OR_ZSH} && ! command grep -qc '^[[:space:]]*[^#[:space:]].*\$NVM_DIR/bash_completion' "$NVM_PROFILE"; then
nvm_echo "=> Appending bash_completion source string to $NVM_PROFILE"
if [ -n "$(command tail -c 1 "$NVM_PROFILE")" ]; then
nvm_echo >> "$NVM_PROFILE"