[Refactor] Improve profile detection in install script

Peter Dave Hello 2017-04-03 23:06:04 +08:00 committed by Jordan Harband
parent d4e3f0943b
commit e84bcaabdc
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
1 changed files with 17 additions and 13 deletions

View File

@ -183,6 +183,13 @@ install_nvm_as_script() {
} }
} }
nvm_try_profile() {
if [ -z "${1-}" ] || [ ! -f "${1}" ]; then
return 1
fi
echo "${1}"
}
# #
# Detect profile file if not specified as environment variable # Detect profile file if not specified as environment variable
# (eg: PROFILE=~/.myprofile) # (eg: PROFILE=~/.myprofile)
@ -211,15 +218,12 @@ nvm_detect_profile() {
fi fi
if [ -z "$DETECTED_PROFILE" ]; then if [ -z "$DETECTED_PROFILE" ]; then
if [ -f "$HOME/.profile" ]; then for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zshrc"
DETECTED_PROFILE="$HOME/.profile" do
elif [ -f "$HOME/.bashrc" ]; then if DETECTED_PROFILE="$(nvm_try_profile "${HOME}/${EACH_PROFILE}")"; then
DETECTED_PROFILE="$HOME/.bashrc" break
elif [ -f "$HOME/.bash_profile" ]; then fi
DETECTED_PROFILE="$HOME/.bash_profile" done
elif [ -f "$HOME/.zshrc" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
fi
fi fi
if [ ! -z "$DETECTED_PROFILE" ]; then if [ ! -z "$DETECTED_PROFILE" ]; then
@ -362,10 +366,10 @@ nvm_do_install() {
# during the execution of the install script # during the execution of the install script
# #
nvm_reset() { nvm_reset() {
unset -f nvm_reset nvm_has nvm_latest_version \ unset -f nvm_has nvm_install_dir nvm_latest_version nvm_profile_is_bash_or_zsh \
nvm_source nvm_download install_nvm_as_script install_nvm_from_git \ nvm_source nvm_node_version nvm_download install_nvm_from_git nvm_install_node \
nvm_detect_profile nvm_check_global_modules nvm_do_install \ install_nvm_as_script nvm_try_profile nvm_detect_profile nvm_check_global_modules \
nvm_install_dir nvm_node_version nvm_install_node nvm_do_install nvm_reset
} }
[ "_$NVM_ENV" = "_testing" ] || nvm_do_install [ "_$NVM_ENV" = "_testing" ] || nvm_do_install