Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,18 @@ 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 '# nvm completions' "$NVM_PROFILE"; then
nvm_echo "=> Skipping nvm source string (found '# nvm completions' marker in ${NVM_PROFILE})"
elif ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then
nvm_echo "=> Appending nvm source string to $NVM_PROFILE"
command printf "${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 '# nvm completions' "$NVM_PROFILE"; then
nvm_echo "=> Skipping bash_completion source string (found '# nvm completions' marker in ${NVM_PROFILE})"
elif ${BASH_OR_ZSH} && ! command grep -qc '$NVM_DIR/bash_completion' "$NVM_PROFILE"; then
nvm_echo "=> Appending bash_completion source string to $NVM_PROFILE"
command printf "$COMPLETION_STR" >> "$NVM_PROFILE"
else
Expand Down
35 changes: 35 additions & 0 deletions test/install_script/nvm_profile_skip_on_marker
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

die () { echo "$@" ; exit 1; }

# Load the install script functions
NVM_ENV=testing \. ../../install.sh

# Simple test to verify the marker check works
echo "Testing profile marker check functionality"

# Create a test profile with marker
TEMP_PROFILE=$(mktemp)
echo "# nvm completions" > "$TEMP_PROFILE"

# Test that grep detects the marker
if command grep -qc '# nvm completions' "$TEMP_PROFILE"; then
echo "Marker detection works"
else
die "Failed to detect '# nvm completions' marker"
fi

# Test profile without marker
TEMP_PROFILE2=$(mktemp)
echo "# some other comment" > "$TEMP_PROFILE2"

if command grep -qc '# nvm completions' "$TEMP_PROFILE2"; then
die "False positive: detected marker when it shouldn't exist"
else
echo "Correctly reports no marker when absent"
fi

# Cleanup
rm -f "$TEMP_PROFILE" "$TEMP_PROFILE2"

echo "All tests passed!"
Loading