There is something suspicious about the error output. Let's look at the first two errors, and think about the fact that your file has a comment as its first line:
: command not found
What command might this be? There is no command name here. Hmm...
'bash: /Users/RGA/.bashrc: line 3: syntax error near unexpected token `{
And: why is there a closing single quote at the beginning of the line, and then an opening single (back)quote near the end of the line, just before the open brace {
?
What if each of these first three lines ends with a mostly-invisible character that, when printed, tells the computer to move back to the first position of the current line? Let's represent this hypothetical mostly-invisible character as \r
, which stands for "invisible character that causes a position-return-to-beginning-of-line". Then the command that is not found is this invisible-character \r
command, and the syntax error occurs because the open brace {
is followed by \r
.
Perhaps we should write this character instead as ^M
, where the M
stands for "motion to beginning of line". Perhaps your first three lines are not:
# Git branch in prompt.
parse_git_branch () {
but rather:
# Git branch in prompt.^M
^M
parse_git_branch () {^M
Perhaps you should view the file with an editor that does not hide carriage-returns \r
(aka ^M
) that occur before newlines \n
.
(If your editor is vim
you can use this setting, which some will probably call overkill, but which I like:
set ffs=unix " disable "file format = dos" detection
Or you can set the file format back once the file is open, so that vim
won't re-add the ^M at the end of each line. If you use some other editor, find out how to make it stop doing automatic DOS-style line endings.)