PS1 bash命令替换不适用于Windows 10

时间:2015-10-19 17:32:15

标签: bash windows-10 ps1

这是我的脚本设置我的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$ "

直到昨天我决定将笔记本电脑更新到Windows 10时才能正常工作。

现在它抛出了这个错误:

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

有关导致此错误的原因的任何想法?

2 个答案:

答案 0 :(得分:11)

问题是ps1中的结束新行。我找到了解决方案here。将我的PS1改为:

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

答案 1 :(得分:1)

我认为错误来自\$(__git_ps1.....

它应该是$(__git_ps1.....(没有'\')

我在(Windows 10 / git 2.10.2)上测试了这个:

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

没问题