5

这是我设置 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 }')'

关于是什么导致此错误的任何想法?

4

2 回答 2

14

问题是 ps1 内结束的新行。我在这里找到了解决方案。将我的 PS1 更改为:

PS1="\n${BBlack}\u@\h ${BRed}\w${BYellow}\$(__git_ps1 ' { %s }')${BGreen}"$'\n$ '
于 2015-10-19T17:46:13.243 回答
0

我认为错误来自这里\$(__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}"

没问题

于 2016-11-13T08:49:30.083 回答