Skip to content
Merged
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: 5 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ nvm_profile_is_bash_or_zsh() {
local TEST_PROFILE
TEST_PROFILE="${1-}"
case "${TEST_PROFILE-}" in
*"/.bashrc" | *"/.bash_profile" | *"/.zshrc")
*"/.bashrc" | *"/.bash_profile" | *"/.zshrc" | *"/.zprofile")
return
;;
*)
Expand Down Expand Up @@ -282,11 +282,13 @@ nvm_detect_profile() {
elif [ "${SHELL#*zsh}" != "$SHELL" ]; then
if [ -f "$HOME/.zshrc" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
elif [ -f "$HOME/.zprofile" ]; then
DETECTED_PROFILE="$HOME/.zprofile"
fi
fi

if [ -z "$DETECTED_PROFILE" ]; then
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zshrc"
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zprofile" ".zshrc"
do
if DETECTED_PROFILE="$(nvm_try_profile "${HOME}/${EACH_PROFILE}")"; then
break
Expand Down Expand Up @@ -415,7 +417,7 @@ nvm_do_install() {
if [ -n "${PROFILE}" ]; then
TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE), "
fi
nvm_echo "=> Profile not found. Tried ${TRIED_PROFILE-}~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."
nvm_echo "=> Profile not found. Tried ${TRIED_PROFILE-}~/.bashrc, ~/.bash_profile, ~/.zprofile, ~/.zshrc, and ~/.profile."
nvm_echo "=> Create one of them and run this script again"
nvm_echo " OR"
nvm_echo "=> Append the following lines to the correct file yourself:"
Expand Down
14 changes: 11 additions & 3 deletions test/install_script/nvm_detect_profile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ setup () {
NVM_ENV=testing \. ../../install.sh
touch ".bashrc"
touch ".bash_profile"
touch ".zprofile"
touch ".zshrc"
touch ".profile"
touch "test_profile"
Expand All @@ -16,7 +17,7 @@ cleanup () {
unset NVM_DETECT_PROFILE
unset SHELL
unset -f setup cleanup die
rm -f ".bashrc" ".bash_profile" ".zshrc" ".profile" "test_profile" > "/dev/null" 2>&1
rm -f ".bashrc" ".bash_profile" ".zprofile" ".zshrc" ".profile" "test_profile" > "/dev/null" 2>&1
}

die () { echo "$@" '$NVM_DETECT_PROFILE:' "$NVM_DETECT_PROFILE"; cleanup; exit 1; }
Expand Down Expand Up @@ -77,7 +78,7 @@ fi

#
# When profile detection fails via both $PROFILE and $SHELL, profile detection should select based on the existence of
# one of the following files is the following order: .profile, .bashrc, .bash_profile, .zshrc and
# one of the following files is the following order: .profile, .bashrc, .bash_profile, .zprofile, .zshrc and
# return an empty value if everything fails
#

Expand All @@ -101,9 +102,16 @@ if [ "$NVM_DETECT_PROFILE" != "$HOME/.bash_profile" ]; then
die "nvm_detect_profile should have selected .bash_profile"
fi

# Otherwise, it should favor .zshrc if file exists
# Otherwise, it should favor .zprofile if file exists
rm ".bash_profile"
NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$HOME/.zprofile" ]; then
die "nvm_detect_profile should have selected .zprofile"
fi

# Otherwise, it should favor .zshrc if file exists
rm ".zprofile"
NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then
die "nvm_detect_profile should have selected .zshrc"
fi
Expand Down
1 change: 1 addition & 0 deletions test/install_script/nvm_profile_is_bash_or_zsh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ type nvm_profile_is_bash_or_zsh > /dev/null 2>&1 || die 'nvm_profile_is_bash_or_
nvm_profile_is_bash_or_zsh "/home/nvm/.bashrc" || die '/home/nvm/.bashrc is bash profile'
nvm_profile_is_bash_or_zsh "/home/nvm/.bash_profile" || die '/home/nvm/.bash_profile is bash profile'
nvm_profile_is_bash_or_zsh "/home/nvm/.zshrc" || die '/home/nvm/.zshrc is zsh profile'
nvm_profile_is_bash_or_zsh "/home/nvm/.zprofile" || die '/home/nvm/.zprofile is zsh profile'
if nvm_profile_is_bash_or_zsh "/home/nvm/.bash"; then die '/home/nvm/.bash is not bash nor zsh profile'; fi
if nvm_profile_is_bash_or_zsh "/home/nvm/.zsh" ; then die '/home/nvm/.zsh is not bash nor zsh profile'; fi