[Fix] `install.sh`: support `~/.zprofile`
parent
c6269e0ac2
commit
7c929f8742
|
@ -40,7 +40,7 @@ nvm_profile_is_bash_or_zsh() {
|
||||||
local TEST_PROFILE
|
local TEST_PROFILE
|
||||||
TEST_PROFILE="${1-}"
|
TEST_PROFILE="${1-}"
|
||||||
case "${TEST_PROFILE-}" in
|
case "${TEST_PROFILE-}" in
|
||||||
*"/.bashrc" | *"/.bash_profile" | *"/.zshrc")
|
*"/.bashrc" | *"/.bash_profile" | *"/.zshrc" | *"/.zprofile")
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -282,11 +282,13 @@ nvm_detect_profile() {
|
||||||
elif [ "${SHELL#*zsh}" != "$SHELL" ]; then
|
elif [ "${SHELL#*zsh}" != "$SHELL" ]; then
|
||||||
if [ -f "$HOME/.zshrc" ]; then
|
if [ -f "$HOME/.zshrc" ]; then
|
||||||
DETECTED_PROFILE="$HOME/.zshrc"
|
DETECTED_PROFILE="$HOME/.zshrc"
|
||||||
|
elif [ -f "$HOME/.zprofile" ]; then
|
||||||
|
DETECTED_PROFILE="$HOME/.zprofile"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$DETECTED_PROFILE" ]; then
|
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
|
do
|
||||||
if DETECTED_PROFILE="$(nvm_try_profile "${HOME}/${EACH_PROFILE}")"; then
|
if DETECTED_PROFILE="$(nvm_try_profile "${HOME}/${EACH_PROFILE}")"; then
|
||||||
break
|
break
|
||||||
|
@ -415,7 +417,7 @@ nvm_do_install() {
|
||||||
if [ -n "${PROFILE}" ]; then
|
if [ -n "${PROFILE}" ]; then
|
||||||
TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE), "
|
TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE), "
|
||||||
fi
|
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 "=> Create one of them and run this script again"
|
||||||
nvm_echo " OR"
|
nvm_echo " OR"
|
||||||
nvm_echo "=> Append the following lines to the correct file yourself:"
|
nvm_echo "=> Append the following lines to the correct file yourself:"
|
||||||
|
|
|
@ -5,6 +5,7 @@ setup () {
|
||||||
NVM_ENV=testing \. ../../install.sh
|
NVM_ENV=testing \. ../../install.sh
|
||||||
touch ".bashrc"
|
touch ".bashrc"
|
||||||
touch ".bash_profile"
|
touch ".bash_profile"
|
||||||
|
touch ".zprofile"
|
||||||
touch ".zshrc"
|
touch ".zshrc"
|
||||||
touch ".profile"
|
touch ".profile"
|
||||||
touch "test_profile"
|
touch "test_profile"
|
||||||
|
@ -16,7 +17,7 @@ cleanup () {
|
||||||
unset NVM_DETECT_PROFILE
|
unset NVM_DETECT_PROFILE
|
||||||
unset SHELL
|
unset SHELL
|
||||||
unset -f setup cleanup die
|
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; }
|
die () { echo "$@" '$NVM_DETECT_PROFILE:' "$NVM_DETECT_PROFILE"; cleanup; exit 1; }
|
||||||
|
@ -77,7 +78,7 @@ fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# When profile detection fails via both $PROFILE and $SHELL, profile detection should select based on the existence of
|
# 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
|
# return an empty value if everything fails
|
||||||
#
|
#
|
||||||
|
|
||||||
|
@ -101,9 +102,16 @@ if [ "$NVM_DETECT_PROFILE" != "$HOME/.bash_profile" ]; then
|
||||||
die "nvm_detect_profile should have selected .bash_profile"
|
die "nvm_detect_profile should have selected .bash_profile"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Otherwise, it should favor .zshrc if file exists
|
# Otherwise, it should favor .zprofile if file exists
|
||||||
rm ".bash_profile"
|
rm ".bash_profile"
|
||||||
NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_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
|
if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then
|
||||||
die "nvm_detect_profile should have selected .zshrc"
|
die "nvm_detect_profile should have selected .zshrc"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -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/.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/.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/.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/.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
|
if nvm_profile_is_bash_or_zsh "/home/nvm/.zsh" ; then die '/home/nvm/.zsh is not bash nor zsh profile'; fi
|
||||||
|
|
Loading…
Reference in New Issue