sdkman / sdkman-hooks

An API responsible for serving up pre- and post- hooks
Other
5 stars 23 forks source link

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

Open theRobinator opened 5 years ago

theRobinator commented 5 years ago

Bash startup is weird and will only read from a single config file when an interactive login shell is started. From the bash man page:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

The old behavior of the install script was to always write to ~/.bash_profile. If a user stored their configuration in .bash_login or .profile, the newly-created .bash_profile would take precedence over the existing file, causing all existing login config to be ignored.

This PR updates the install script to append our init snippet to whatever file the user is already using, only creating a new .bash_profile if no files already exist.