Suggest to create .bash_profile if it doesn't exist

This commit is contained in:
Julian Ospald 2019-11-05 11:58:37 +08:00
parent 42e8989d0b
commit 2e3968d500
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
1 changed files with 28 additions and 15 deletions

View File

@ -100,29 +100,42 @@ if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
GHCUP_PROFILE_FILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ] ; then
GHCUP_PROFILE_FILE="$HOME/.bash_profile"
else
# most complaints we get are from mac users who
# need assistance of setting up their shell, so suggest
# to create .bash_profile, which is a good guess
GHCUP_PROFILE_FILE="$HOME/.bash_profile"
fi
if [ -n "${GHCUP_PROFILE_FILE}" ] && [ -f "${GHCUP_PROFILE_FILE}" ] ; then
if [ -f "${GHCUP_PROFILE_FILE}" ] ; then
printf "\\033[0;35m%s\\033[0m\\n" ""
printf "\\033[0;35m%s\\033[0m\\n" "Detected \"${GHCUP_PROFILE_FILE}\" on your system..."
printf "\\033[0;35m%s\\033[0m\\n" "If you want ghcup to automatically fix your \"${GHCUP_PROFILE_FILE}\" to include the required PATH variable"
printf "\\033[0;35m%s\\033[0m\\n" "answer with YES, otherwise with NO and press ENTER."
printf "\\033[0;35m%s\\033[0m\\n" ""
while true; do
read -r next_answer </dev/tty
case $next_answer in
[Yy]*)
echo "source $GHCUP_INSTALL_BASE_PREFIX/.ghcup/env" >> "${GHCUP_PROFILE_FILE}"
exit 0;;
[Nn]*)
exit 0;;
*)
echo "Please type YES or NO and press enter.";;
esac
done
elif [ -n "${BASH}" ] ; then # only suggest to create .bash_profile if we are in a bash shell
printf "\\033[0;35m%s\\033[0m\\n" ""
printf "\\033[0;35m%s\\033[0m\\n" "Detected bash shell on your system..."
printf "\\033[0;35m%s\\033[0m\\n" "If you want ghcup to automatically create \"${GHCUP_PROFILE_FILE}\" and include the required PATH variable"
printf "\\033[0;35m%s\\033[0m\\n" "answer with YES, otherwise with NO and press ENTER."
printf "\\033[0;35m%s\\033[0m\\n" ""
else
exit 0
fi
while true; do
read -r next_answer </dev/tty
case $next_answer in
[Yy]*)
echo "source $GHCUP_INSTALL_BASE_PREFIX/.ghcup/env" >> "${GHCUP_PROFILE_FILE}"
exit 0;;
[Nn]*)
exit 0;;
*)
echo "Please type YES or NO and press enter.";;
esac
done
fi
)