Skip to content

[Fix] Ignore commented profile source lines - #3860

Draft
Vaibhav-C-S wants to merge 4 commits into
nvm-sh:masterfrom
Vaibhav-C-S:fix-commented-profile-lines
Draft

[Fix] Ignore commented profile source lines#3860
Vaibhav-C-S wants to merge 4 commits into
nvm-sh:masterfrom
Vaibhav-C-S:fix-commented-profile-lines

Conversation

@Vaibhav-C-S

Copy link
Copy Markdown

Fixes: #1889

This updates the install script so commented-out nvm profile lines are not treated as active setup lines.

Before this change, install.sh checked for /nvm.sh and $NVM_DIR/bash_completion anywhere in the profile file. This also matched commented-out lines as well.

# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

As a result, reinstalling nvm skipped appending active setup lines. After opening a new bash shell with that profile, nvm was still unavailable:

$ nvm --version
bash: nvm: command not found

After this change, the installer ignores commented-out setup lines and appends active nvm and bash_completion lines:

=> Appending nvm source string to ~/.bashrc
=> Appending bash_completion source string to ~/.bashrc

Hence, nvm is available as expected:

$ nvm --version
0.40.5

@Vaibhav-C-S

Copy link
Copy Markdown
Author

Hi @ljharb , can you please look at this pr, when you have time, it is a small and focused fix.

@chalamohammed069-sys

This comment was marked as spam.

@slow6r

This comment was marked as spam.

@ljharb ljharb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! This will need regression tests, though.

@ljharb
ljharb marked this pull request as draft July 9, 2026 05:11
@Vaibhav-C-S
Vaibhav-C-S marked this pull request as ready for review July 9, 2026 14:29
@Vaibhav-C-S
Vaibhav-C-S marked this pull request as draft July 9, 2026 14:29
Comment thread install.sh
BASH_OR_ZSH=true
fi
if ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then
if ! command grep -qc '^[[:space:]]*[^#].*/nvm\.sh' "$NVM_PROFILE"; then

@ljharb ljharb Jul 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This still matches indented comments - [[:space:]]* backtracks, so [^#] can itself match a space: a line like # [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" (or a tab-indented one) is still treated as active, and the #1889 repro persists for it.

Excluding whitespace from the guard class fixes it without breaking indented active lines:

'^[[:space:]]*[^#[:space:]].*/nvm\.sh'

(the $NVM_DIR/bash_completion pattern below has the same issue)

The regression tests should include an indented-comment case, since that is the case that distinguishes this pattern from the correct one.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks @ljharb will work on the regex fix and will add regression tests.

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.

nvm install script fails to detect commented out nvm source string and bash_completion in ~/.bashrc

4 participants