Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash_prompt throw error in git-bash #582

Open
fredyang opened this issue Sep 21, 2015 · 9 comments
Open

bash_prompt throw error in git-bash #582

fredyang opened this issue Sep 21, 2015 · 9 comments

Comments

@fredyang
Copy link

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

@cemo
Copy link

cemo commented Sep 22, 2015

duplicates #544

@munirwanis
Copy link

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

@Tatsh
Copy link

Tatsh commented May 3, 2016

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.

@munirwanis
Copy link

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

@Tatsh
Copy link

Tatsh commented May 3, 2016

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
Copy link

Tatsh commented May 3, 2016

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.

@munirwanis
Copy link

munirwanis commented May 4, 2016

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

@xxxwarrior
Copy link

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.

@plankan39
Copy link

plankan39 commented Dec 10, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants