在 Windows 上的 Git Bash 中设置提示颜色

问题描述 投票:0回答:2

我已经成功地尝试了 Windows 上 Git Bash 中的一些颜色设置 - 我可以设置一些内容,例如我的

.gitconfig
文件中的本地、当前和远程分支的颜色:

[color "branch"]
current = cyan bold
local = cyan 
remote = red

但是我没能改变的是提示的颜色 - 行开头的

username@machine
(在我的屏幕截图中的黄色矩形中),以及我当前所在的项目和分支(紫色矩形) ).

enter image description here

是否也有办法影响这些?我需要设置哪些

.gitconfig
设置才能更改这些颜色?

git bash msysgit
2个回答
15
投票

在您的

.bashrc
中,您可以使用
PS1
变量设置提示(该变量可能设置为
/etc/profile
中的全局值或
/etc
中的另一个文件,这可能取决于发行版)。

这是一个例子:

PS1='\[\033[1;36m\]\u@\h:\[\033[0m\]\[\033[1;34m\]\w\[\033[0m\] \[\033[1;32m\]$(__git_ps1)\[\033[0m\]\$ '

为了使命令替换起作用,您需要

shopt -s promptvars
,这是默认值。

这将在使用

TERM=xterm-color
的终端上以青色输出用户和主机名,以蓝色输出当前目录,以绿色输出 git 分支。

有关终端控制的更多信息,请参阅

man 5 terminfo
man tput


0
投票

我最近发现,在位于用户文件夹中的

.bashrc
文件中,有部分脚本:

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

取消注释时,将向

PS1
变量添加颜色位:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

否则,设置简单提示

© www.soinside.com 2019 - 2024. All rights reserved.