在 VCS 中使 shell 提示符显示当前头
使用VCS时(我在Linux中使用Mercurial和Git,Bash提示符),有什么办法让提示符显示目录中当前的头或标签?
不止一次,我搬起石头砸自己的脚,因为我以为自己在另一个头脑中工作,例如,在他们需要 v.02 时将 v0.3 推向测试,或者修补 dev
中的错误然后需要在 prod 中修补它们,反之亦然。
When using a VCS, (I use Mercurial and Git in Linux, Bash prompt), is there any way to have the prompt show the current head or tag in the directory?
More than once I have shot myself in the foot by working in one head when thinking I was in another, for example, pushing v0.3 to testing when they needed v.02, or patching bugs in dev
then they needed to be patched in prod
, or vice versa.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
对于 Mercurial,有 Steve Losh 编写的 hg-prompt。这是 Mercurial 的扩展,为您提供了新的
hg Prompt
命令。您将此命令的调用放入您的PS1
环境变量中:以获得类似于
末尾的
?
的提示,告诉您存储库中存在未知文件。Steve 写了一篇关于他的 Zsh 提示符的博客文章,其中有文档中的更多彩色提示:
For Mercurial, there is hg-prompt by Steve Losh. This is an extension for Mercurial that gives you a new
hg prompt
command. You put a call to this command into yourPS1
environment variable:to get a prompt like
where the
?
at the end tells you that there is an unknown file in your repository.Steve wrote a blog post about his Zsh prompt and there are more colorful prompts from the documentation:
Git 提供了一个 bash 函数,可以显示当前分支或哈希(如果是无头的)。在 bash_completion 文件中查找 __git_ps1。
我的
~/.bashrc
包含以下几行:这将创建如下提示:
Git provides a bash function that shows the current branch or hash if headless. Look for __git_ps1 in the bash_completion file.
My
~/.bashrc
contains these lines:which will create a prompt like this:
看看 git-prompt。它将自己描述为“带有 GIT、SVN 和 HG 模块的 bash 提示符”。
对于 git,你可以做得更容易:只需加载 bash-completion 模块(只需
source git-completion.bash
- 你会在 git 源代码树中的某个位置找到该文件,或者如果你安装了git 使用包管理器将 bash 完成模块放在 git 的任何文件夹中,并在提示符中使用__git_ps1
,例如通过export PS1='w$(__git_ps1 “(%s)”)> '
Have a look at git-prompt. It describes itself as a "bash prompt with GIT, SVN and HG modules".
Just for git you can do it much easier though: simply load the bash-completion module (simply
source git-completion.bash
- you'll find the file somewhere in the git source tree or if you installed git using your package manager in whatever folder it puts bash completion modules) of git and use__git_ps1
in your prompt, e.g. viaexport PS1='w$(__git_ps1 "(%s)") > '
值得一看 http://stevelosh.com/blog/ 2010/02/my-extravagant-zsh-prompt/。 Git 和 Mercurial,以及大量其他信息。
即使您不想要他的确切提示,它也提供了有关他如何构建它的大量信息。
It's worth taking a look at http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/. Git and Mercurial, plus a load of other information.
Even if you don't want his exact prompt it provides a lot of information on how he built it up.
请查看 http://vcprompt.com/。它是用 Python 编写的,跨平台的,您只需下载它并将其放入 bin 目录即可。它支持 bzr、cvs、darcs、fossil、git、hg 和 svn。
Have a look at http://vcprompt.com/. It's written in Python, cross-platform, and you can simply download it and drop it into your bin directory. It supports bzr, cvs, darcs, fossil, git, hg and svn.
这是 Mercurial bash 提示:
它扩展为如下所示:
Here's a Mercurial bash prompt:
Which expands to something like this: