-# See if the bashrc file is involved with .dotfiles at all
-if [ ! -e _bashrc ]; then
- # No _bashrc file, so leave ~/.bashrc alone
- exit
+if [ $BASH_RC == "yes" ]; then
+ # We may have a dotfiles section in ~/.bashrc. Strip it out.
+ BC="### ---- begin .dotfiles section ---- (keep this magic comment)"
+ EC="### ---- end .dotfiles section ---- (keep this magic comment)"
+ AWKSCRIPT="BEGIN{copy=1}{"
+ AWKSCRIPT="$AWKSCRIPT if(\$0 == \"$BC\"){copy=0};"
+ AWKSCRIPT="$AWKSCRIPT if(\$0 == \"$EC\"){copy=1};"
+ AWKSCRIPT="$AWKSCRIPT if(copy==1 && \$0 != \"$EC\"){print \$0}"
+ AWKSCRIPT="$AWKSCRIPT}"
+
+ awk "$AWKSCRIPT" ~/.bashrc > bashrc_stripped
+
+ # see if the stripped file is any different
+ DIFF=`diff ~/.bashrc bashrc_stripped` || exit 1
+ if [ -n "$DIFF" ]; then
+ rm -f ~/.bashrc
+ cp bashrc_stripped ~/.bashrc
+ fi