Skip to content

Commit e72e72e

Browse files
committed
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`.
1 parent 86c1e3c commit e72e72e

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

install.sh

+12-13
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,14 @@ function _bash-it_backup_new() {
7272

7373
# Back up existing profile and append bash-it templates at the end
7474
function _bash-it_backup_append() {
75+
local profile_strings=('if [[ -f ~/.profile ]]; then' 'source ~/.profile' 'fi' 'if [[ -f ~/.bashrc ]]; then' 'source ~/.bashrc' 'fi')
7576
_bash-it_backup
7677
(sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" | tail -n +2) >> "$HOME/$CONFIG_FILE"
78+
if [[ ! -f ~/.bash_profile ]]; then
79+
printf '%s\n\t%s\n%s\n%s\n\t%s\n%s\n' "${profile_strings[@]}" > ~/.bash_profile
80+
else
81+
printf '\e[0;33m%s\n\t%s\n\t\t%s\n\t%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[@]}"
82+
fi
7783
echo -e "\033[0;32mBash-it template has been added to your $CONFIG_FILE\033[0m"
7884
}
7985

@@ -186,14 +192,7 @@ fi
186192

187193
BASH_IT="$(cd "${BASH_SOURCE%/*}" && pwd)"
188194

189-
case $OSTYPE in
190-
darwin*)
191-
CONFIG_FILE=.bash_profile
192-
;;
193-
*)
194-
CONFIG_FILE=.bashrc
195-
;;
196-
esac
195+
CONFIG_FILE=.bashrc
197196

198197
BACKUP_FILE=$CONFIG_FILE.bak
199198
echo "Installing bash-it"
@@ -205,13 +204,13 @@ fi
205204
export BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE=''
206205
# Load dependencies for enabling components
207206
# shellcheck disable=SC1090
208-
source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh
209-
# shellcheck source=./lib/utilities.bash
207+
source "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
208+
cite _about _param _example _group _author _version
209+
# shellcheck source-path=SCRIPTDIR/lib
210210
source "$BASH_IT/lib/utilities.bash"
211-
# shellcheck source=./lib/log.bash
211+
# shellcheck source-path=SCRIPTDIR/lib
212212
source "${BASH_IT}/lib/log.bash"
213-
cite _about _param _example _group _author _version
214-
# shellcheck source=./lib/helpers.bash
213+
# shellcheck source-path=SCRIPTDIR/lib
215214
source "$BASH_IT/lib/helpers.bash"
216215

217216
if [[ -n $interactive && -z "${silent}" ]]; then

0 commit comments

Comments
 (0)