Sylar
Sylar

Reputation: 12072

Git Autocompletion: syntax error near unexpected token `newline'

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?

Upvotes: 7

Views: 7814

Answers (6)

HEMANTA
HEMANTA

Reputation: 71

=>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

Upvotes: 0

FelipeC
FelipeC

Reputation: 9488

You are using the wrong URL:

curl -o ~/.git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash

Upvotes: 0

Kelvin
Kelvin

Reputation: 1172

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.

Upvotes: 0

Jayveer Parmar
Jayveer Parmar

Reputation: 500

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.

Upvotes: 1

Jay
Jay

Reputation: 427

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.

Upvotes: 5

Nobu
Nobu

Reputation: 10425

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.

Upvotes: -1

Related Questions