[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
Provenance
- Commit
7c929f8- Tree
3f6497a- Author
Maxim Lepekha <m.lepekha@yandex.ru>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
c6269e0
3 files changed+17 added−6 removed
modified:test/install_script/nvm_detect_profile+11 added-3 removed
3 unmodified lines4 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 lines16 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 }22 23 die () { echo "$@" '$NVM_DETECT_PROFILE:' "$NVM_DETECT_PROFILE"; cleanup; exit 1; }24 52 unmodified lines77 fi78 79 #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 #84 85 # It should favor .profile if file exists15 unmodified lines101 if [ "$NVM_DETECT_PROFILE" != "$HOME/.bash_profile" ]; then102 die "nvm_detect_profile should have selected .bash_profile"103 fi104 104-# Otherwise, it should favor .zshrc if file exists105+# Otherwise, it should favor .zprofile if file exists106 rm ".bash_profile"107 NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"108+if [ "$NVM_DETECT_PROFILE" != "$HOME/.zprofile" ]; then109+ die "nvm_detect_profile should have selected .zprofile"110+fi111+112+# Otherwise, it should favor .zshrc if file exists113+rm ".zprofile"114+NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"115 if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then116 die "nvm_detect_profile should have selected .zshrc"117 fi118 8 unmodified linesmodified:test/install_script/nvm_profile_is_bash_or_zsh+1 added
7 unmodified lines8 type nvm_profile_is_bash_or_zsh > /dev/null 2>&1 || die 'nvm_profile_is_bash_or_zsh is not available'9 nvm_profile_is_bash_or_zsh "/home/nvm/.bashrc" || die '/home/nvm/.bashrc is bash profile'10 nvm_profile_is_bash_or_zsh "/home/nvm/.bash_profile" || die '/home/nvm/.bash_profile is bash profile'11 nvm_profile_is_bash_or_zsh "/home/nvm/.zshrc" || die '/home/nvm/.zshrc is zsh profile'12+nvm_profile_is_bash_or_zsh "/home/nvm/.zprofile" || die '/home/nvm/.zprofile is zsh profile'13 if nvm_profile_is_bash_or_zsh "/home/nvm/.bash"; then die '/home/nvm/.bash is not bash nor zsh profile'; fi14 if nvm_profile_is_bash_or_zsh "/home/nvm/.zsh" ; then die '/home/nvm/.zsh is not bash nor zsh profile'; fimodified:install.sh+5 added-3 removed
38 unmodified lines39 nvm_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 1233 unmodified lines281 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 fi289 290 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 fi120 unmodified lines416 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