From 6ae9d7081d82f58e862796d754a7d21b7a3f750b Mon Sep 17 00:00:00 2001 From: Justin Dray Date: Mon, 14 Sep 2015 13:58:40 +0000 Subject: [PATCH] Fix bash_profile creation breaking bashrc on Linux Made additions to .bashrc unless .bash_profile exists. If bash_profile is created, then .bashrc will be ignored. .bash_profile is the default on OS X however. --- keyring.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/keyring.sh b/keyring.sh index 0ef7ecf..0042381 100755 --- a/keyring.sh +++ b/keyring.sh @@ -21,7 +21,7 @@ install() { install-bashrc add-key ~/.ssh/id_rsa - PS1='$ ' source ~/.bash_profile + PS1='$ ' source $BASHRC } install_linux() { @@ -71,19 +71,24 @@ install-bashrc() { alias ssh-add=\"$SCRIPT ssh-add\" fi" - CODE_EXISTS=$(grep "$SCRIPT ssh-add" ~/.bash_profile || echo) + if [[ -e ~/.bash_profile ]]; then + BASHRC="$HOME/.bash_profile" + else + BASHRC="$HOME/.bashrc" + fi + CODE_EXISTS=$(grep "$SCRIPT ssh-add" $BASHRC || echo) if [ ! -z "$CODE_EXISTS" ]; then - echo "It looks like the ssh-agent code is already in your ~/.bash_profile file. Skipping." + echo "It looks like the ssh-agent code is already in your $BASHRC file. Skipping." else echo - echo "This code will be added to your ~/.bash_profile:" + echo "This code will be added to your $BASHRC:" echo echo "$CODE" echo echo -n "Do you want to proceed [Y/n]? " read ANSWER if [[ ! "$ANSWER" =~ ^[Nn]$ ]]; then - echo "$CODE" >> ~/.bash_profile + echo "$CODE" >> $BASHRC fi fi