Improve shell detection in bootstrap-haskell wrt #121

This commit is contained in:
Julian Ospald 2019-11-26 12:20:13 +08:00
parent 6afec9094d
commit 7034131632
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28

View File

@ -96,39 +96,50 @@ if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
echo "You may want to source '$GHCUP_INSTALL_BASE_PREFIX/.ghcup/env' in your shell" echo "You may want to source '$GHCUP_INSTALL_BASE_PREFIX/.ghcup/env' in your shell"
echo "configuration to do so (e.g. ~/.bashrc)." echo "configuration to do so (e.g. ~/.bashrc)."
if [ -f "$HOME/.bashrc" ] ; then case $SHELL in
GHCUP_PROFILE_FILE="$HOME/.bashrc" */zsh) # login shell is zsh
elif [ -f "$HOME/.bash_profile" ] ; then GHCUP_PROFILE_FILE="$HOME/.zshrc"
GHCUP_PROFILE_FILE="$HOME/.bash_profile" MY_SHELL="zsh" ;;
else */bash) # login shell is bash
# most complaints we get are from mac users who if [ -f "$HOME/.bashrc" ] ; then # bashrc is not sourced by default, so assume it isn't if file does not exist
# need assistance of setting up their shell, so suggest GHCUP_PROFILE_FILE="$HOME/.bashrc"
# to create .bash_profile, which is a good guess else
GHCUP_PROFILE_FILE="$HOME/.bash_profile" GHCUP_PROFILE_FILE="$HOME/.bash_profile"
fi fi
if [ -f "${GHCUP_PROFILE_FILE}" ] ; then MY_SHELL="bash" ;;
printf "\\033[0;35m%s\\033[0m\\n" "" */sh) # login shell is sh, but might be a symlink to bash or zsh
printf "\\033[0;35m%s\\033[0m\\n" "Detected \"${GHCUP_PROFILE_FILE}\" on your system..." if [ -n "${BASH}" ] ; then
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" if [ -f "$HOME/.bashrc" ] ; then # bashrc is not sourced by default, so assume it isn't if file does not exist
printf "\\033[0;35m%s\\033[0m\\n" "answer with YES, otherwise with NO and press ENTER." GHCUP_PROFILE_FILE="$HOME/.bashrc"
printf "\\033[0;35m%s\\033[0m\\n" "" else
elif [ -n "${BASH}" ] ; then # only suggest to create .bash_profile if we are in a bash shell GHCUP_PROFILE_FILE="$HOME/.bash_profile"
printf "\\033[0;35m%s\\033[0m\\n" "" fi
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" MY_SHELL="bash"
printf "\\033[0;35m%s\\033[0m\\n" "answer with YES, otherwise with NO and press ENTER." elif [ -n "${ZSH_VERSION}" ] ; then
printf "\\033[0;35m%s\\033[0m\\n" "" GHCUP_PROFILE_FILE="$HOME/.zshrc"
else MY_SHELL="zsh"
exit 0 else
fi exit 0
fi
;;
*) exit 0 ;;
esac
printf "\\033[0;35m%s\\033[0m\\n" ""
printf "\\033[0;35m%s\\033[0m\\n" "Detected ${MY_SHELL} shell on your system..."
printf "\\033[0;35m%s\\033[0m\\n" "If you want ghcup to automatically add the required PATH variable to \"${GHCUP_PROFILE_FILE}\""
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 while true; do
read -r next_answer </dev/tty read -r next_answer </dev/tty
case $next_answer in case $next_answer in
[Yy]*) [Yy]*)
echo "source $GHCUP_INSTALL_BASE_PREFIX/.ghcup/env" >> "${GHCUP_PROFILE_FILE}" echo "[ -f \"\${GHCUP_INSTALL_BASE_PREFIX:=\$HOME}/.ghcup/env\" ] && source \"\${GHCUP_INSTALL_BASE_PREFIX:=\$HOME}/.ghcup/env\"" >> "${GHCUP_PROFILE_FILE}"
printf "\\033[0;35m%s\\033[0m\\n" "OK! ${GHCUP_PROFILE_FILE} has been modified. Restart your terminal for the changes to take effect," printf "\\033[0;35m%s\\033[0m\\n" "OK! ${GHCUP_PROFILE_FILE} has been modified. Restart your terminal for the changes to take effect,"
printf "\\033[0;35m%s\\033[0m\\n" "or type \"source ${GHCUP_INSTALL_BASE_PREFIX}/.ghcup/env\" to apply them in your current terminal session." printf "\\033[0;35m%s\\033[0m\\n" "or type \"source ${GHCUP_INSTALL_BASE_PREFIX}/.ghcup/env\" to apply them in your current terminal session."
exit 0;; exit 0;;