为什么我的bash提示符更新? [英] Why doesn't my bash prompt update?

查看:115
本文介绍了为什么我的bash提示符更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的git,我想当前的git分支添加到我的已经存在的提示,其定义如下:

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} "

我想它(通过获取我的的.bashrc 再次文件),它似乎工作,但后来我去另一个分支,并没有更新。我怎样才能确保 $(__ git_ps1)是不缓存?

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?

推荐答案

您需要在 $ 反斜线所以它不会立即展开。 (比较到``... ,这是写 $(...)以不同的方式。 )

You need a backslash on the $ so it isn't expanded immediately. (Compare to the `...`, which is a different way of writing $(...).)

export PS1="${RESET}${YELLOW}\u@\h${NORMAL} \`${SELECT}\` ${YELLOW}\w \$(__git_ps1) >${NORMAL} "

我会@MikeSep同意有关使用单引号,但它实际上是更理想一点,让颜色等立即被取代。没有必要的,只是稍微好一些。这就是说,它的的更容易理解发生了什么事情,如果你使用单引号。

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.

这篇关于为什么我的bash提示符更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆