dotfiles
dotfiles copied to clipboard
bash_prompt throw error in git-bash
A bash shell is bundled with latest version git for window, it seems does not support the .bash_prompt in line https://github.com/mathiasbynens/dotfiles/blob/master/.bash_prompt#L114
The error is
bash: command substitution: line 1: syntax error near unexpected token )' bash: command substitution: line 1:
prompt_git " on ")'
To me it is legal, so I don't know how to fix it. Can this be fixed for git-bash (bash for git for window)?
Thanks
duplicates #544
I'm having the same problem and I don't think this is duplicated.
This repository targets Bash 4.x on OS X. It may work on Linux/BSD, even the Windows version of Bash that comes with Git for Windows. It may even work on zsh or other similar shells. For anything that is not Bash 4 (regardless of how you upgrade OS X's) and OS X, you are on your own.
Unsupported environments should be ignored.
@fredyang
@Tatsh I am using bash for windows.
I discovered the solution! The problem was at the PS1+="\n"
line!
Just change .bash_prompt
file this line for that one:
PS1+=$'\n';
Is it worth to send a pull request? It affects OS X and Linux prompts?
Well, I am not sure about that since my PS1 used on Linux and Mac does not seem to have this problem but it has \n
within. PS1 is not interpreted exactly like a Bash string (yes you use a Bash string to create it). You want non-literal \n
for later processing when PS1 is rendered, which means the original line is not incorrect, just as you want \h
(hostname) and not literally \h
to show up in your prompt.
This may be some sort of weird bug with Bash for Windows. On Cygwin Bash I do not get this problem.
See the reference manual section Controlling the Prompt. It seems to me that your Bash has \n
not being decoded properly. It would not surprise me if this is specific to Bash for Windows because of something strange in the Windows console API.
I'm using minGW, it comes with git for windows. Maybe the problem is just with minGW decoding since you are using Cygwin bash and it works ok! Thanks for the help @Tatsh
Just in case someone is looking for the workaround.
I've changed this line PS1+="\$(prompt_git \"\[${white}\] on \[${violet}\]\" \"\[${blue}\]\")";
to PS1+="\`prompt_git \"\[${white}\] on \[${violet}\]\" \"\[${blue}\]\"\`";
and it works.
@xxxwarrior is on to something, however, you must wrap the shell command with \[
\]
, similarly to when you set colors. The line should be : PS1+="\[\`prompt_git \"\[${white}\] on \[${violet}\]\" \"\[${blue}\]\"\`\]";