diff --git a/install-bashhub.sh b/install-bashhub.sh index 2d3d2914e2827497b9e04c275e0e53fc6e0e4b7f..fca912e19087e9ee7536144af00ab0d5800ba400 100755 --- a/install-bashhub.sh +++ b/install-bashhub.sh @@ -22,6 +22,12 @@ if [ -f ~/.bashhub/bashhub.zsh ]; then fi ' +bash_config_source=' +if [ -f ~/.bashrc ]; then + source ~/.bashrc +fi +' + python_command=' import sys if (2, 6, 0) < sys.version_info < (3,0): @@ -133,12 +139,39 @@ install_hooks_for_zsh() { } + +# Create two config files .bashrc and .bash_profile since +# OS X and Linux shells use them diffferently. Source .bashrc +# from .bash_profile and everything should work the same now. +generate_bash_config_file() { + touch ~/.bashrc + touch ~/.bash_profile + echo "$bash_config_source" >> ~/.bash_profile + echo "Created ~/.bash_profile and ~/.bashrc" +} + + install_hooks_for_bash() { local bashprofile=$(find_users_bash_file) + + # If we don't have a bash profile ask if we should generate one. + if [ -z "$bashprofile" ]; then + echo "Couldn't find a bash confg file." + + while true; do + read -p "Would you like to generate one? (y/n): " yn + case $yn in + [Yy]* ) generate_bash_config_file; bashprofile="$HOME/.bashrc"; break;; + [Nn]* ) break;; + * ) echo "Please answer yes or no.";; + esac + done + fi + # Have to have this. Error out otherwise. if [ -z "$bashprofile" ]; then - die "No bashfile (e.g. .profile, .bashrc, etc) could be found" 1 + die "No bashfile (e.g. .profile, .bashrc, etc) could be found." 1 fi # Add our file to our bashprofile if it doesn't exist yet diff --git a/tests/shell/install-bashhub.fake-home.bats b/tests/shell/install-bashhub.fake-home.bats index e8d900572dd0204594cdd121dc15b33ad7ff1000..f607590e8606f2a7c64819ea9d7847133fcd7d56 100644 --- a/tests/shell/install-bashhub.fake-home.bats +++ b/tests/shell/install-bashhub.fake-home.bats @@ -44,3 +44,15 @@ install_bashhub() { [[ $status == 1 ]] } +@test "generate .bash_profile and .bashrc and link them" { + rm ~/.bashrc + rm ~/.zshrc + run 'generate_bash_config_file' + [[ $status == 0 ]] + [[ -f ~/.bashrc ]] + [[ -f ~/.bash_profile ]] + # Should source .bashrc in .bash_profile + in_profile=$(grep -q 'source ~/.bashrc' ~/.bash_profile; echo $?;) + [[ "$in_profile" == 0 ]] +} +