使用GIT_PS1_SHOWCOLORHINTS自定义__git_ps1的颜色 [英] Customize colors for __git_ps1 with GIT_PS1_SHOWCOLORHINTS

查看:587
本文介绍了使用GIT_PS1_SHOWCOLORHINTS自定义__git_ps1的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经更新了提示,使用 __ git_ps1 包含了分支名称。此外,我还设置了 GIT_PS1_SHOWCOLORHINTS

I have updated my prompt to include the branch name using __git_ps1. In addition, I set GIT_PS1_SHOWCOLORHINTS.

提示正确显示。但是,分支颜色始终为绿色。

The prompt appears correctly. However, the branch color is always green. I expected a dirty branch to be red.

文档状态:

The docs state:


这些颜色基于git status -sb的颜色输出。

The colors are based on the colored output of "git status -sb"

我发现并审阅了如何着色git-status输出?但我不知道我需要改变什么选项.. 。

I found and reviewed How to colorize git-status output? But I'm not sure what options I'd need to change...

是否可以将分支颜色更改为绿色分支和红色的分支?如果是这样,怎么样?

Is it possible to change the branch color to be green for a clean branch and red for a dirty branch? If so, how?

推荐答案

显示的颜色由 __ git_ps1 分支机构不影响分行名称;它们会影响脏状态指示器。除了启用颜色之外,如果启用此指示器,则会看到一个脏分支的红色星号:

The colours shown by __git_ps1 for dirty branches don't affect the branch name; they affect the "dirty state indicator". In addition to enabling colours, if you enable this indicator you will see a red asterisk for a dirty branch:

old-prompt $ bash --noprofile --norc
bash-4.2$ source /etc/bash_completion.d/git-prompt
bash-4.2$ export GIT_PS1_SHOWCOLORHINTS=1
bash-4.2$ export GIT_PS1_SHOWDIRTYSTATE=1
bash-4.2$ export PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
chris@machine:~/path/to/dir (master *)$

无法根据脏东西来更改分支名称的颜色无需修改 git-prompt.sh 代码或提供自己的函数。

There is no way to change the colour of the branch name based on dirty status without modifying the git-prompt.sh code, or providing your own function.

请注意,这适用于 export PROMPT_COMMAND 但不是 export PS1

Note that this works with export PROMPT_COMMAND but not export PS1.

这篇关于使用GIT_PS1_SHOWCOLORHINTS自定义__git_ps1的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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