7

I have looked at different questions regarding this issue and none seem identical to mine: new git installation on Mac 10.10.2

I have used the below to install auto-completion:

curl -OL https://github.com/git/git/blob/master/contrib/completion/git-completion.bash

I have also tried the above with: -O.

I have added a . to the file that was downloaded:

mv ~/git-completion.bash ~/.git-completion.bash

Then I edit my bash_profile and inserted the line to get an auto load when terminal loads:

if [ -f ~/.git-completion.bash ]; then
  source ~/.git-completion.bash
fi

Up on restarting terminal:

Users/user/.git-completion.bash: line 4: syntax error near unexpected token `newline'

Is there an issue with the file that was download or my OS?

Sylar
  • 11,422
  • 25
  • 93
  • 166
  • Have you looked at the file you downloaded to see what it contains? Running that command gets me an HTML page as output. – Etan Reisner Feb 26 '15 at 18:03
  • @EtanReisner You must have missed off the `-OL`. I've downloaded the correct file – Sylar Feb 26 '15 at 18:07
  • Nope. Copied and pasted that command literally. What version of curl? Check your file again? Can you put lines 1-5 of the file in your post? – Etan Reisner Feb 26 '15 at 18:08
  • 1
    F sake it's the wrong file. This works: `https://github.com/git/git/raw/master/contrib/completion/git-completion.bash` – Sylar Feb 26 '15 at 18:11
  • And you get the error with that correct file? Because line four is a comment in that file. Does running `dos2unix` on that file help? Also doesn't git-bash come with completion enabled by default? – Etan Reisner Feb 26 '15 at 18:16
  • Can you possibly edit your question? I stumbled upon this post using google and spent 10 minutes copy pasting your problem line before seeing this comment section. The accepted answer does not fix your wrong URL problem, so this page currently only contains harmful information. – cjbooms Sep 18 '15 at 08:50
  • 1
    Maybe you did not grab the raw file. See here: [http://stackoverflow.com/questions/27192662/need-help-loading-a-git-completion-bash-file](http://stackoverflow.com/questions/27192662/need-help-loading-a-git-completion-bash-file) – Vagelis Prokopiou Oct 16 '16 at 11:03

6 Answers6

5
curl -OL https://github.com/git/git/blob/master/contrib/completion/git-completion.bash

this is not real '.bash' file. (looks like website html file)

if you want to git-completion.bash file,

connect site "https://github.com/git/git"

and

click on the "Download ZIP" button

thanks.

Jay
  • 397
  • 1
  • 5
  • 19
  • 1
    Nope, totally wrong. Right url for this is: https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash. So ```curl -OL https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash``` – luminousmen Sep 05 '17 at 11:41
1

I found a solution. I had an exact same error as yours.

  1. Download file from https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash and save as .bash file
  2. Open terminal
  3. Delete any previous git-completion.bash file if any in your user folder
  4. copy your downloaded file to user folder
  5. Type following in terminal, make sure you are in user directory mv ~/git-completion.bash ~/.git-completion.bash
  6. Type in terminal nano .bash_profile
  7. ctr+x for mac user
  8. enter following code

    `if [ -f ~/.git-completion.bash ]; then
        source ~/.git-completion.bash
     fi`
    
  9. Press ctr+x for exiting .bash_profile, select 'Y'
  10. Close the terminal and re-open it.
  11. For checking auto completion, type git h and press tab key for autocompletion of help.
Jayveer Parmar
  • 500
  • 7
  • 25
0

The problem is caused by the newline characters in the downloaded file. So you can press the 'raw' button on the github page and copy the raw content of the script. Then replace the content of git-completion.bash with the raw content using your text editor, save it and good to go.

Kelvin
  • 1,082
  • 2
  • 12
  • 23
0

You are using the wrong URL:

curl -o ~/.git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
FelipeC
  • 9,123
  • 4
  • 44
  • 38
0

=>For Mac User

=> Install homebrew

=> Install Git and bash-completion: brew install git && brew install bash-completion (Note: If this install fails with a 404 error, and you already have git installed, just remove the git part of this brew install)

=> Add bash-completion to your ~/.bash_profile:

if [ -f brew --prefix/etc/bash_completion.d/git-completion.bash ]; then . brew --prefix/etc/bash_completion.d/git-completion.bash fi

HEMANTA
  • 71
  • 7
-1

I got a similar error: git-completion.bash: line 155: syntax error near unexpected token. The file looked fine, so I did brew install bash and the error's gone. Current one is 4.3.39 and previous one was:

$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14)

Hope it helps for those who googled error message.

Nobu
  • 9,965
  • 4
  • 40
  • 47