Skip to content
Myr

[Fix] `install.sh`: support `~/.zprofile`

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Maxim Lepekha · committed by Jordan Harband · parent c6269e0 · Browse files · 3 files+17 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+17 added−6 removed

  • tests:+12 added−3 removed
  • other:+5 added−3 removed

3 files+17 added−6 removed

modified:test/install_script/nvm_detect_profile+11 added-3 removed
3 unmodified lines
4 HOME="."5 NVM_ENV=testing \. ../../install.sh6 touch ".bashrc"7 touch ".bash_profile"8 touch ".zprofile"9 touch ".zshrc"10 touch ".profile"11 touch "test_profile"12}
3 unmodified lines
16 unset NVM_ENV17 unset NVM_DETECT_PROFILE18 unset SHELL19 unset -f setup cleanup die19 rm -f ".bashrc" ".bash_profile" ".zshrc" ".profile" "test_profile" > "/dev/null" 2>&120 rm -f ".bashrc" ".bash_profile" ".zprofile" ".zshrc" ".profile" "test_profile" > "/dev/null" 2>&121}2223die () { echo "$@" '$NVM_DETECT_PROFILE:' "$NVM_DETECT_PROFILE"; cleanup; exit 1; }24
52 unmodified lines
77fi7879#80# When profile detection fails via both $PROFILE and $SHELL, profile detection should select based on the existence of80# one of the following files is the following order: .profile, .bashrc, .bash_profile, .zshrc and81# one of the following files is the following order: .profile, .bashrc, .bash_profile, .zprofile, .zshrc and82# return an empty value if everything fails83#8485# It should favor .profile if file exists
15 unmodified lines
101if [ "$NVM_DETECT_PROFILE" != "$HOME/.bash_profile" ]; then102 die "nvm_detect_profile should have selected .bash_profile"103fi104104# Otherwise, it should favor .zshrc if file exists105# Otherwise, it should favor .zprofile if file exists106rm ".bash_profile"107NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"108if [ "$NVM_DETECT_PROFILE" != "$HOME/.zprofile" ]; then109 die "nvm_detect_profile should have selected .zprofile"110fi111112# Otherwise, it should favor .zshrc if file exists113rm ".zprofile"114NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"115if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then116 die "nvm_detect_profile should have selected .zshrc"117fi118
8 unmodified lines
modified:test/install_script/nvm_profile_is_bash_or_zsh+1 added
7 unmodified lines
8type nvm_profile_is_bash_or_zsh > /dev/null 2>&1 || die 'nvm_profile_is_bash_or_zsh is not available'9nvm_profile_is_bash_or_zsh "/home/nvm/.bashrc" || die '/home/nvm/.bashrc is bash profile'10nvm_profile_is_bash_or_zsh "/home/nvm/.bash_profile" || die '/home/nvm/.bash_profile is bash profile'11nvm_profile_is_bash_or_zsh "/home/nvm/.zshrc" || die '/home/nvm/.zshrc is zsh profile'12nvm_profile_is_bash_or_zsh "/home/nvm/.zprofile" || die '/home/nvm/.zprofile is zsh profile'13if nvm_profile_is_bash_or_zsh "/home/nvm/.bash"; then die '/home/nvm/.bash is not bash nor zsh profile'; fi14if nvm_profile_is_bash_or_zsh "/home/nvm/.zsh" ; then die '/home/nvm/.zsh is not bash nor zsh profile'; fi
modified:install.sh+5 added-3 removed
38 unmodified lines
39nvm_profile_is_bash_or_zsh() {40 local TEST_PROFILE41 TEST_PROFILE="${1-}"42 case "${TEST_PROFILE-}" in43 *"/.bashrc" | *"/.bash_profile" | *"/.zshrc")43 *"/.bashrc" | *"/.bash_profile" | *"/.zshrc" | *"/.zprofile")44 return45 ;;46 *)47 return 1
233 unmodified lines
281 fi282 elif [ "${SHELL#*zsh}" != "$SHELL" ]; then283 if [ -f "$HOME/.zshrc" ]; then284 DETECTED_PROFILE="$HOME/.zshrc"285 elif [ -f "$HOME/.zprofile" ]; then286 DETECTED_PROFILE="$HOME/.zprofile"287 fi288 fi289290 if [ -z "$DETECTED_PROFILE" ]; then289 for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zshrc"291 for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zprofile" ".zshrc"292 do293 if DETECTED_PROFILE="$(nvm_try_profile "${HOME}/${EACH_PROFILE}")"; then294 break295 fi
120 unmodified lines
416 local TRIED_PROFILE417 if [ -n "${PROFILE}" ]; then418 TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE), "419 fi418 nvm_echo "=> Profile not found. Tried ${TRIED_PROFILE-}~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."420 nvm_echo "=> Profile not found. Tried ${TRIED_PROFILE-}~/.bashrc, ~/.bash_profile, ~/.zprofile, ~/.zshrc, and ~/.profile."421 nvm_echo "=> Create one of them and run this script again"422 nvm_echo " OR"423 nvm_echo "=> Append the following lines to the correct file yourself:"424 command printf "${SOURCE_STR}"
55 unmodified lines