user4826780
user4826780

Reputation:

git config --global returns "syntax error near unexpected token `)'" error

When I try:

$ git config --global user.name "Me"

it returns me this error:

bash: command substitution: line 1: syntax error near unexpected token `)'
bash: command substitution: line 1: `__git_ps1)'

I'm running Git 2.6.3 on Windows 7 at C:\opt\git-2.6.3 and my .gitconfig was - at first - empty.

But, beside this error, it was filled with:

[user]
name = Me

and, for each command that I type, the Prompt returns me the same error...

How can I fix this?

With gratitude,

Upvotes: 5

Views: 5943

Answers (2)

Alan Jay Weiner
Alan Jay Weiner

Reputation: 1129

I also traced it to the \n following $(__git_ps1)

Simplifying the PS1 prompt:

This works:

PS1='$(__git_ps1)'

This does not; it gives the syntax error message:

PS1='$(__git_ps1)\n'

However, giving the \n in ASCII does work:

PS1='$(__git_ps1)\012'

Interestingly, after the \012 you can use \n again:

PS1='$(__git_ps1)\012\n'

Note: I found additional errors in my PS1; not sure if they were there before, something odd happened when I updated git, or maybe (probably!) from my messing around in the distant past...

My PS1 (after updating git earlier today) was:

PS1='\[\033]0;$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]\n\[\033[32m\]\u@\h \[\033[33m\]\w \[\033[1m\]\[\033[31m\]$(__git_ps1)\[\033[0m\]\n$ '

This gives the syntax error, but also that first escape sequence is wrong:

wrong!   PS1='\[\033]0;$MSYSTEM ...
right!   PS1='\[\033[0;m$MSYSTEM ...

the bracket after \033 was backwards and the 'm' was missing...

My corrected PS1 is now:

PS1='\[\033[0;m$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]\n\[\033[32m\]\u@\h \[\033[33m\]\w \[\033[1m\]\[\033[31m\]$(__git_ps1)\[\033[0m\]\012$ '

this gives my prompt as:

MINGW64:/c/Users/aweiner       <-white
aweiner@ajw-sony ~             <- green, dir in yellow, git branch name in red
$

(and yes, it's way verbose, so I'll probably mess with it some more...)

Upvotes: 16

Nickolay Merkin
Nickolay Merkin

Reputation: 2743

This is an issue with git bash interpreter.

I have bisected the definition of PS1 in my .profile, and found that the problem appears if there were \n somewhere AFTER $(blablabla). Even "blablabla" is absolutely innocent, like echo helloworld.

My solution was to emit the linefeed using another function:

function echonewline() {
  echo -e "\n "
  # last line must be non-empty - I emit a whitespace
}

PS1=\n...all...stuff...$(__git_ps1)...colors...$(echonewline) $
# newlines before first function call are welcome.

Looks weird, but it works.

Git bash v. 2.8.2 for Windows.

Upvotes: 6

Related Questions