dotfiles icon indicating copy to clipboard operation
dotfiles copied to clipboard

bash_prompt throw error in git-bash

Open fredyang opened this issue 9 years ago • 9 comments

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

fredyang avatar Sep 21 '15 19:09 fredyang

duplicates #544

cemo avatar Sep 22 '15 05:09 cemo

I'm having the same problem and I don't think this is duplicated.

munirwanis avatar May 02 '16 15:05 munirwanis

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.

Tatsh avatar May 03 '16 04:05 Tatsh

@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?

munirwanis avatar May 03 '16 14:05 munirwanis

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.

Tatsh avatar May 03 '16 14:05 Tatsh

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.

Tatsh avatar May 03 '16 14:05 Tatsh

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

munirwanis avatar May 04 '16 14:05 munirwanis

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 avatar Aug 12 '20 17:08 xxxwarrior

@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}\]\"\`\]";

plankan39 avatar Dec 10 '20 12:12 plankan39