This commit is contained in:
Michael Martinez 2015-02-07 20:51:05 +00:00
commit 49a8ec9560
1 changed files with 20 additions and 13 deletions

View File

@ -100,26 +100,33 @@ install_nvm_as_script() {
} }
} }
#
# Detect profile file if not specified as environment variable # Detect profile file if not specified as environment variable
# (eg: PROFILE=~/.myprofile) # (eg: PROFILE=~/.myprofile)
# The echo'ed path is guaranteed to be an existing file # The echo'ed path is guaranteed to be an existing file
# Otherwise, an empty string is returned # Otherwise, an empty string is returned
# #
# Auto detects the appropriate shell by looking at the shell of
# the caller process and login/interactive status.
nvm_detect_profile() { nvm_detect_profile() {
if [ -f "$PROFILE" ]; then local shell=$(ps $PPID | tail -n 1 | awk '{print $(NF-0)}')
echo "$PROFILE" if [ -f "$PROFILE" ]; then
elif [ -f "$HOME/.bashrc" ]; then echo "$PROFILE"
echo "$HOME/.bashrc" elif echo $shell | grep -q "zsh"; then
elif [ -f "$HOME/.bash_profile" ]; then echo "$HOME/.zshrc"
echo "$HOME/.bash_profile" elif echo $shell | grep -q "bash"; then
elif [ -f "$HOME/.zshrc" ]; then local login_status=$(shopt -q login_shell)
echo "$HOME/.zshrc" local interactive_status=$([[ $- == *i* ]])
elif [ -f "$HOME/.profile" ]; then if [[ $login_status -eq 0 ]]; then
echo "$HOME/.profile" echo "$HOME/.bashrc"
fi elif [[ $interactive_status -eq 0 ]]; then
echo "$HOME/.bash_profile"
fi
else
echo ""
fi
} }
nvm_do_install() { nvm_do_install() {
if [ -z "$METHOD" ]; then if [ -z "$METHOD" ]; then
# Autodetect install method # Autodetect install method