From e6ac356a6c8b4f6b396ae93051fb6b2f9788faf5 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 12 Jan 2022 21:06:57 -0800 Subject: [PATCH] install: use `.bashrc` and notify user The logic to guess whether to use `.bash_profile` or `.bashrc` was buggy and wrong. Just use `.bashrc` and either automatically fill in a `.bash_profile`, or notify the user that they need to edit their `.bash_profile`. --- install.sh | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/install.sh b/install.sh index 2bb78a3f64..99f3720b6e 100755 --- a/install.sh +++ b/install.sh @@ -72,8 +72,14 @@ function _bash-it_backup_new() { # Back up existing profile and append bash-it templates at the end function _bash-it_backup_append() { + local profile_strings=('if [[ -f ~/.bashrc ]]; then' 'source ~/.bashrc' 'fi') _bash-it_backup (sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" | tail -n +2) >> "$HOME/$CONFIG_FILE" + if [[ ! -f ~/.bash_profile && ! -f ~/.bash_login && ! -f ~/.profile ]]; then + printf '%s\n\t%s\n%s\n' "${profile_strings[@]}" > ~/.bash_profile + else + printf '\e[0;33m%s\n\t%s\n\t\t%s\n\t%s\n\e[0m' "You may need to update your ~/.bash_profile (or ~/.profile) to source your ~/.bashrc:" "${profile_strings[@]}" + fi echo -e "\033[0;32mBash-it template has been added to your $CONFIG_FILE\033[0m" } @@ -186,14 +192,7 @@ fi BASH_IT="$(cd "${BASH_SOURCE%/*}" && pwd)" -case $OSTYPE in - darwin*) - CONFIG_FILE=.bash_profile - ;; - *) - CONFIG_FILE=.bashrc - ;; -esac +CONFIG_FILE=.bashrc BACKUP_FILE=$CONFIG_FILE.bak echo "Installing bash-it" @@ -205,13 +204,13 @@ fi export BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE='' # Load dependencies for enabling components # shellcheck disable=SC1090 -source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh -# shellcheck source=./lib/utilities.bash +source "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" +cite _about _param _example _group _author _version +# shellcheck source-path=SCRIPTDIR/lib source "$BASH_IT/lib/utilities.bash" -# shellcheck source=./lib/log.bash +# shellcheck source-path=SCRIPTDIR/lib source "${BASH_IT}/lib/log.bash" -cite _about _param _example _group _author _version -# shellcheck source=./lib/helpers.bash +# shellcheck source-path=SCRIPTDIR/lib source "$BASH_IT/lib/helpers.bash" if [[ -n $interactive && -z "${silent}" ]]; then