Skip to content

Commit

Permalink
install: use .bashrc and notify user
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
gaelicWizard committed Jan 13, 2022
1 parent 86c1e3c commit e2f1ce3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
25 changes: 12 additions & 13 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ~/.profile ]]; then' 'source ~/.profile' 'fi' '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 ]]; then
printf '%s\n\t%s\n%s\n%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\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"
}

Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
11 changes: 2 additions & 9 deletions test/install/install.bats
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@
load ../test_helper

# Determine which config file to use based on OS.
case $OSTYPE in
darwin*)
export BASH_IT_CONFIG_FILE=.bash_profile
;;
*)
export BASH_IT_CONFIG_FILE=.bashrc
;;
esac
export BASH_IT_CONFIG_FILE=.bashrc

function local_setup {
setup_test_fixture
Expand Down Expand Up @@ -78,7 +71,7 @@ function local_setup {
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak"

run cat $BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE
run cat "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"

assert_line "test file content"
assert_line "source \"\$BASH_IT\"/bash_it.sh"
Expand Down

0 comments on commit e2f1ce3

Please sign in to comment.