5

This is my script that sets up my bash PS1

# Reset
Color_Off="\[\033[0m\]"       # Text Reset

# Regular Colors
Black="\[\033[0;30m\]"        # Black
Red="\[\033[0;31m\]"          # Red
Green="\[\033[0;32m\]"        # Green
Yellow="\[\033[0;33m\]"       # Yellow
Blue="\[\033[0;34m\]"         # Blue
Purple="\[\033[0;35m\]"       # Purple
Cyan="\[\033[0;36m\]"         # Cyan
White="\[\033[0;37m\]"        # White

# Bold
BBlack="\[\033[1;30m\]"       # Black
BRed="\[\033[1;31m\]"         # Red
BGreen="\[\033[1;32m\]"       # Green
BYellow="\[\033[1;33m\]"      # Yellow
BBlue="\[\033[1;34m\]"        # Blue
BPurple="\[\033[1;35m\]"      # Purple
BCyan="\[\033[1;36m\]"        # Cyan
BWhite="\[\033[1;37m\]"       # White

# Various variables you might want for your PS1 prompt instead
Time12h="\T"
Time12a="\@"
PathShort="\w"
PathFull="\W"
NewLine="\n"
Jobs="\j"

GIT_PS1_SHOWDIRTYSTATE="true"

PS1="\n${BBlack}\u@\h ${BRed}\w${BYellow}\$(__git_ps1 ' { %s }')${BGreen}\n$ "

It was working perfectly until yesterday when I decided to update my laptop to windows 10.

Now it throws this error:

bash: command substitution: line 1: syntax error near unexpected token `)'
bash: command substitution: line 1: `__git_ps1 ' { %s }')'

Any idea on what is causing this error?

StefanoGermani
  • 721
  • 7
  • 18

2 Answers2

14

The problem is the ending new line inside the ps1. I found the solution here. Changed my PS1 to:

PS1="\n${BBlack}\u@\h ${BRed}\w${BYellow}\$(__git_ps1 ' { %s }')${BGreen}"$'\n$ '
StefanoGermani
  • 721
  • 7
  • 18
  • Good find. I've always preferred a single line prompt `PS1="\[\e[0;37m\]\D{%R}\[\e[1;34m\] \h:\w> \[\e[0m\]"` Give it a spin (I use a dark xterm). – David C. Rankin Oct 19 '15 at 18:33
  • helped me too, thanks! had to change a line in Git\etc\profile, restart console, works like a charm. – FloppyNotFound Nov 19 '15 at 10:28
  • When you use the double quote for the PS1="bla bla" it refresh automatically when you enter and exit a folder with a .git repo? Because my bash 4.3.42(5)-release (x86_64-pc-msys) only refresh when you login in the specific directory and then it stuck with the branch name even if I change directories. – tvl May 26 '16 at 11:17
  • 1
    Nice find, literally removing the `'\n'` fixed the problem. I also tried your solution of appending the `$'\n$ '` to replace the new line with a dollar and that worked for me too! Thanks! – Sooth Sep 13 '16 at 17:20
0

I think the error comes from here \$(__git_ps1.....

It should be $(__git_ps1..... (without '\')

I have tested this on (windows 10 / git 2.10.2):

PS1="\n${White}\u@\h ${BRed}\w${BYellow} $(__git_ps1 ' { %s }')${BGreen}\n$ ${Color_Off}"

and no problem

clinton3141
  • 4,751
  • 3
  • 33
  • 46
Athmailer
  • 129
  • 1
  • 4