Skip to content

Use the existing bash init file in Darwin to avoid accidentally overriding existing config #15

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 16 additions & 4 deletions app/views/install.scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ sdkman_archives_folder="${SDKMAN_DIR}/archives"
sdkman_candidates_folder="${SDKMAN_DIR}/candidates"
sdkman_config_file="${sdkman_etc_folder}/config"
sdkman_bash_profile="${HOME}/.bash_profile"
sdkman_bash_login="${HOME}/.bash_login"
sdkman_profile="${HOME}/.profile"
sdkman_bashrc="${HOME}/.bashrc"
sdkman_zshrc="${HOME}/.zshrc"
Expand Down Expand Up @@ -266,11 +267,22 @@ echo "$SDKMAN_VERSION" > "${SDKMAN_DIR}/var/version"


if [[ $darwin == true ]]; then
touch "$sdkman_bash_profile"
# Bash only reads one of the following config files, in this order. Write to the one that the user is already using if possible.
if [[ -e "$sdkman_bash_profile" ]]; then
sdkman_init_file="$sdkman_bash_profile"
elif [[ -e "$sdkman_bash_login" ]]; then
sdkman_init_file="$sdkman_bash_login"
elif [[ -e "$sdkman_profile" ]]; then
sdkman_init_file="$sdkman_profile"
else
# Default to creating .bash_profile as it's the least likely to be overridden in the future
sdkman_init_file="$sdkman_bash_profile"
fi
touch "$sdkman_init_file"
echo "Attempt update of login bash profile on OSX..."
if [[ -z $(grep 'sdkman-init.sh' "$sdkman_bash_profile") ]]; then
echo -e "\n$sdkman_init_snippet" >> "$sdkman_bash_profile"
echo "Added sdkman init snippet to $sdkman_bash_profile"
if [[ -z $(grep 'sdkman-init.sh' "$sdkman_init_file") ]]; then
echo -e "\n$sdkman_init_snippet" >> "$sdkman_init_file"
echo "Added sdkman init snippet to $sdkman_init_file"
fi
else
echo "Attempt update of interactive bash profile on regular UNIX..."
Expand Down