如何修改 cygwin 的 PS1 以进行 git bash 完成?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21140815/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 09:15:47  来源:igfitidea点击:

How do I modify cygwin's PS1 for git bash completion?

gitbashcygwingit-bash

提问by void.pointer

Here is my current PS1:

这是我目前的 PS1:

$ echo $PS1
\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n$

I have installed git bash completion and it isn't showing the current branch in my command prompt. I think this needs to be edited but I've got no idea what to change to make it show the current branch. Note that I like the colors and general structure (i.e. with $on its own line), so I'd like to keep that if possible.

我已经安装了 git bash completion,但它没有在我的命令提示符中显示当前分支。我认为这需要编辑,但我不知道要更改什么才能使其显示当前分支。请注意,我喜欢颜色和一般结构(即$在自己的行中),所以如果可能的话,我想保留它。

回答by Chris

Modify the prompt string and add $(__git_ps1 " (%s)")somewhere.

修改提示字符串并在$(__git_ps1 " (%s)")某处添加。

For example, try typing this into Bash:

例如,尝试在 Bash 中输入以下内容:

export PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]$(__git_ps1 ' (%s)')\n$"

Once you find something you like, add that line to one of Bash's startup files, e.g. $HOME/.bashrc.

找到喜欢的内容后,将该行添加到 Bash 的启动文件之一,例如$HOME/.bashrc.

The source for git-prompt.shis well-commented and worth browsing if you're curious about other options.

如果您对其他选项感到好奇,的来源git-prompt.sh得到了很好的评论,值得浏览。

Note that you may have to manually source path/to/git-prompt.shbefore this will work. If so, add this line to your config file as well, above the export PS1bit.

请注意,您可能必须手动操作source path/to/git-prompt.sh才能使用。如果是这样,请将此行也添加到您的配置文件中,export PS1在位上方。