为什么我的 bash 提示符没有更新?
我是 git 新手,我正在尝试将当前 git 分支添加到我已经存在的提示符中,其定义如下:
RESET="\[\017\]"
NORMAL="\[\033[0m\]"
RED="\[\033[31;1m\]"
YELLOW="\[\033[33;1m\]"
WHITE="\[\033[37;1m\]"
SMILEY="${WHITE}:)${NORMAL}"
FROWNY="${RED}:(${NORMAL}"
SELECT="if [ \$? = 0 ]; then echo \"${SMILEY}\"; else echo \"${FROWNY}\"; fi"
export PS1="${RESET}${YELLOW}\u@\h${NORMAL} \`${SELECT}\` ${YELLOW}\w $(__git_ps1) >${NORMAL} "
我尝试了它(通过再次获取我的 .bashrc
文件)并且它似乎有效,但后来我转到另一个分支,但它没有更新。如何确保 $(__git_ps1)
未缓存?
I'm new to git and I'm trying to add the current git branch to my already existing prompt, which is defined as follows :
RESET="\[\017\]"
NORMAL="\[\033[0m\]"
RED="\[\033[31;1m\]"
YELLOW="\[\033[33;1m\]"
WHITE="\[\033[37;1m\]"
SMILEY="${WHITE}:)${NORMAL}"
FROWNY="${RED}:(${NORMAL}"
SELECT="if [ \$? = 0 ]; then echo \"${SMILEY}\"; else echo \"${FROWNY}\"; fi"
export PS1="${RESET}${YELLOW}\u@\h${NORMAL} \`${SELECT}\` ${YELLOW}\w $(__git_ps1) >${NORMAL} "
I tried it (by sourcing my .bashrc
file again) and it seemed to work, but then I went on another branch and it did not update. How can I make sure the $(__git_ps1)
is not cached?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
PS1
字符串可能会在保存之前进行评估,但您确实希望每次收到命令提示符时都运行__git_ps1
命令。我建议您在export PS1='${RESET}...'
行中使用单引号而不是双引号。Your
PS1
string is probably getting evaluated before it is getting saved, but you really want the__git_ps1
command to run each time you get a command prompt. I'd recommend using single quotes instead of double quotes for yourexport PS1='${RESET}...'
line.$
上需要有一个反斜杠,这样它就不会立即展开。 (与`...`
相比,这是$(...)
的不同编写方式。)我同意 @MikeSep 关于使用单引号的观点,但实际上让颜色等立即被替换是更优化的。没必要,稍微好一点就好了。也就是说,如果使用单引号,更容易理解发生了什么。
You need a backslash on the
$
so it isn't expanded immediately. (Compare to the`...`
, which is a different way of writing$(...)
.)I would agree with @MikeSep about using single quotes, but it's actually a bit more optimal to let the colors and such be substituted immediately. Not necessary, just somewhat better. That said, it is easier to understand what's going on if you use the single quotes.