Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install.sh: prefer placing shellenv command in rcfile rather than shell profile on Linux #809

Merged
merged 3 commits into from
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1014,22 +1014,27 @@ EOS
ohai "Next steps:"
case "${SHELL}" in
*/bash*)
if [[ -r "${HOME}/.bash_profile" ]]
if [[ -n "${HOMEBREW_ON_LINUX-}" ]]
then
shell_profile="${HOME}/.bash_profile"
shell_rcfile="${HOME}/.bashrc"
else
shell_profile="${HOME}/.profile"
shell_rcfile="${HOME}/.bash_profile"
fi
;;
*/zsh*)
shell_profile="${HOME}/.zprofile"
if [[ -n "${HOMEBREW_ON_LINUX-}" ]]
then
shell_rcfile="${ZDOTDIR:-"${HOME}"}/.zshrc"
else
shell_rcfile="${ZDOTDIR:-"${HOME}"}/.zprofile"
fi
;;
*)
shell_profile="${HOME}/.profile"
shell_rcfile="${ENV:-"${HOME}/.profile"}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reference for the ENV environment variable:

Stack Overflow: Is there an alternative for .bashrc for /bin/sh?

;;
esac

if grep -qs "eval \"\$(${HOMEBREW_PREFIX}/bin/brew shellenv)\"" "${shell_profile}"
if grep -qs "eval \"\$(${HOMEBREW_PREFIX}/bin/brew shellenv)\"" "${shell_rcfile}"
then
if ! [[ -x "$(command -v brew)" ]]
then
Expand All @@ -1041,7 +1046,7 @@ EOS
else
cat <<EOS
- Run these two commands in your terminal to add Homebrew to your ${tty_bold}PATH${tty_reset}:
(echo; echo 'eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"') >> ${shell_profile}
(echo; echo 'eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"') >> ${shell_rcfile}
eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"
EOS
fi
Expand All @@ -1054,8 +1059,8 @@ then
plural="s"
fi
printf -- "- Run these commands in your terminal to add the non-default Git remote%s for %s:\n" "${plural}" "${non_default_repos}"
printf " echo '# Set PATH, MANPATH, etc., for Homebrew.' >> %s\n" "${shell_profile}"
printf " echo '%s' >> ${shell_profile}\n" "${additional_shellenv_commands[@]}"
printf " echo '# Set PATH, MANPATH, etc., for Homebrew.' >> %s\n" "${shell_rcfile}"
printf " echo '%s' >> ${shell_rcfile}\n" "${additional_shellenv_commands[@]}"
printf " %s\n" "${additional_shellenv_commands[@]}"
fi

Expand Down