在VCS中使shell提示符显示当前头部

cc *_*ung 8 git version-control mercurial dvcs command-prompt

使用VCS时(我在Linux中使用Mercurial和Git,Bash提示),有没有办法让提示显示目录中的当前头或标记?

我不止一次在认为自己在另一个人的脑袋里时,用自己的脑袋开枪,例如,当他们需要v.02推动v0.3进行测试,或者修补bug时,dev他们需要修补prod,或相反亦然.

Mar*_*ler 9

对于Mercurial来说,史蒂夫·洛什(Steve Losh)有hg-prompt.这是Mercurial的扩展,它为您提供了一个新hg prompt命令.您将此命令的调用放入PS1环境变量中:

export PS1='\u in \w`hg prompt "{on {branch}}{status}{update}" 2>/dev/null` $'
Run Code Online (Sandbox Code Playgroud)

得到一个提示

user in ~/src/project on feature-branch? $
Run Code Online (Sandbox Code Playgroud)

其中?在最后告诉你,没有在你的仓库未知的文件.

史蒂夫写了一篇关于他的Zsh提示博客文章,文档中有更多彩色提示:

史蒂夫的多彩提示


JRi*_*out 3

Git 提供了一个 bash 函数,可以显示当前分支或哈希(如果是无头的)。在bash_completion文件中查找 __git_ps1 。

我的~/.bashrc包含这些行:

Green='\[\e[0;32m\]'
BIGreen='\[\e[1;92m\]'
Color_Off='\[\e[0m\]'
export PS1=$Green'\w $(__git_ps1 "(%s)")'$BIGreen'$ '$Color_Off
Run Code Online (Sandbox Code Playgroud)

这将创建一个像这样的提示:

~/repos/myproject (master)$ 
Run Code Online (Sandbox Code Playgroud)