Skip to content

Commit

Permalink
[Refctor] Improve profile detection in install script
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterDaveHello committed Apr 3, 2017
1 parent 424056c commit 5de4453
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ install_nvm_as_script() {
}
}

nvm_try_profile() {
local PROFILE_PATH
PROFILE_PATH="${1}"
if [ ! -f "${PROFILE_PATH}" ]; then
return 1
fi
echo "${PROFILE_PATH}"
}

#
# Detect profile file if not specified as environment variable
# (eg: PROFILE=~/.myprofile)
Expand Down Expand Up @@ -211,15 +220,12 @@ nvm_detect_profile() {
fi

if [ -z "$DETECTED_PROFILE" ]; then
if [ -f "$HOME/.profile" ]; then
DETECTED_PROFILE="$HOME/.profile"
elif [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
elif [ -f "$HOME/.zshrc" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
fi
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zshrc"
do
if DETECTED_PROFILE=$(nvm_try_profile "${HOME}/${EACH_PROFILE}"); then
break
fi
done
fi

if [ ! -z "$DETECTED_PROFILE" ]; then
Expand Down

0 comments on commit 5de4453

Please sign in to comment.