如何在 Windows 的 Git Bash 中更改 RGB 颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21243172/
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-09 11:18:04  来源:igfitidea点击:

How to change RGB colors in Git Bash for windows?

windowsgitshellmsysgit

提问by void.pointer

I'm using the Git Bash in Windows and for the purposes of my custom git logformat, I'd like to modify the terminal's exact RGB color values so I can fine-tune the color outputs. My git log format is as follows in my global .gitconfig:

我在 Windows 中使用 Git Bash,出于自定义git log格式的目的,我想修改终端的确切 RGB 颜色值,以便我可以微调颜色输出。我的 git 日志格式在我的 global 中如下.gitconfig

lg1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset)%x09%C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset) %C(dim white)%an%C(reset) - %C(white)%s%C(reset)' --branches --remotes --tags

I'd like to define in Git Bash what RGB value actually maps to 'blue', for example. Any idea how I can do this? Step by step instructions would be wonderful. Thanks in advance.

例如,我想在 Git Bash 中定义实际映射到“蓝色”的 RGB 值。知道我该怎么做吗?分步说明会很棒。提前致谢。

EDIT

编辑

I setup my .bashrc and it isn't working for some reason. Colors aren't changing :-(. Here is a script I ran to see colors: http://pastebin.com/9EsYmGCjand the result: http://i.imgur.com/1dJ3o1a.png

我设置了我的 .bashrc,但由于某种原因它不起作用。颜色没有改变:-(。这是我运行的脚本来查看颜色:http: //pastebin.com/9EsYmGCj和结果:http: //i.imgur.com/1dJ3o1a.png

回答by StaticNoiseLog

This works for me to change the text colors used by Git Bash on Windows 7:

这对我来说可以更改 Windows 7 上 Git Bash 使用的文本颜色:

  • Click on the upper left corner of an open Git Bash window (the Git icon in the window frame).
  • A menu appears (the same that would appear with a regular DOS cmd Window). Choose the last entry: "Properties"
  • Go to tab "Colors"
  • Choose radio button "Screen Text"
  • Remember which color is currently assigned to "Screen Text" in the row of small color boxes (it has a black frame).
  • Then select the color you want to change by clicking on the corresponding color box. This color is now assigned as "Screen Text", which is what Git Bash uses for regular text. But don't worry, this change is only temporary and needed to modify the value of a color.
  • Now change the Red/Green/Blue values for the selected color. In my case I wanted to make the fifth color from the left (much) brighter. Let's call it "Color 5". This is the color Git Bash uses to show changed files with "git status". Whenever Git Bash wants to use "Color 5" it will use the new RGB value.
  • "Screen Text" is now still set to "Color 5". So click on the original color that you have remembered.
  • 单击打开的 Git Bash 窗口的左上角(窗口框架中的 Git 图标)。
  • 出现一个菜单(与常规 DOS cmd 窗口中出现的菜单相同)。选择最后一个条目:“属性”
  • 转到选项卡“颜色”
  • 选择单选按钮“屏幕文本”
  • 记住当前分配给小颜色框行中的“屏幕文本”的颜色(它有一个黑框)。
  • 然后通过单击相应的颜色框选择要更改的颜色。这种颜色现在被指定为“屏幕文本”,这是 Git Bash 用于常规文本的颜色。不过别担心,这个改变只是暂时的,需要修改颜色的值。
  • 现在更改所选颜色的红/绿/蓝值。在我的例子中,我想让左边的第五种颜色(更)更亮。我们称之为“颜色 5”。这是 Git Bash 用来显示带有“git status”的更改文件的颜色。每当 Git Bash 想要使用“颜色 5”时,它都会使用新的 RGB 值。
  • “屏幕文本”现在仍设置为“颜色 5”。因此,单击您记住的原始颜色。

The changes made in this way are permanent but only valid for the shortcut you have used to start Git Bash. If you create a new shortcut you are back to the original colors.

以这种方式所做的更改是永久性的,但仅对您用于启动 Git Bash 的快捷方式有效。如果您创建一个新的快捷方式,您将回到原来的颜色。

回答by user2044859

If you are using the git-bash command prompt check if you have the file: %USERPROFILE%\.minttyrc
In that file you can fine tune the RGB values of the console colors in this way:

如果您使用 git-bash 命令提示符,请检查您是否有文件:%USERPROFILE%\.minttyrc
在该文件中,您可以通过以下方式微调控制台颜色的 RGB 值:

BoldBlack=128,128,128
Red=255,64,40
BoldRed=255,128,64
Green=64,200,64
BoldGreen=64,255,64
Yellow=190,190,0
BoldYellow=255,255,64
Blue=0,128,255
BoldBlue=128,160,255
Magenta=200,64,255
BoldMagenta=255,128,255
Cyan=64,190,190
BoldCyan=128,255,255
White=200,200,200
BoldWhite=255,255,255

回答by David Galloway

For those of you coming here to get an answer to the actual Original Question the answer is to add the following line to the end of:

对于那些来到这里以获得实际原始问题答案的人,答案是在末尾添加以下行:

C:\Program Files\Git\etc\profile.d\git-prompt.sh


LS_COLORS=$LS_COLORS:'di=1;30:' ; export LS_COLORS

You may chose from these colors.

您可以从这些颜色中进行选择。

Black       0;30     Dark Gray     1;30
Blue        0;34     Light Blue    1;34
Green       0;32     Light Green   1;32
Cyan        0;36     Light Cyan    1;36
Red         0;31     Light Red     1;31
Purple      0;35     Light Purple  1;35
Brown       0;33     Yellow        1;33
Light Gray  0;37     White         1;37

回答by Dave Hughes

When using MSYSGIT, Git Bash runs in the Windows Command Prompt. Consequently, it uses the colors defined for the terminal. Since Git Bash is a command that is always run, you can set its colors in the Command Prompt's Properties, rather than Defaults.

使用 MSYSGIT 时,Git Bash 在 Windows 命令提示符中运行。因此,它使用为终端定义的颜色。由于 Git Bash 是一个始终运行的命令,您可以在命令提示符的Properties 中设置其颜色,而不是Defaults

For instructions on changing the terminal colors, see: https://superuser.com/questions/199764/how-to-change-the-default-color-of-the-command-prompt

有关更改终端颜色的说明,请参阅:https: //superuser.com/questions/199764/how-to-change-the-default-color-of-the-command-prompt



Note: I've found the Command Prompt's color options to be a huge pain to configure, as they frequently changed/reset while editing. The trick seems to be to tab out of the input boxes after editing.

注意:我发现命令提示符的颜色选项配置起来非常麻烦,因为它们在编辑时经常更改/重置。诀窍似乎是在编辑后退出输入框。

回答by Roland Ettinger

Why so complicated? Git bash uses the default Windows console colors which may be tweaked in the registry. E.g. to increase readability, one can change the dark red and the dark magenta to a lighter version by applying the changes as indicated below:

为什么这么复杂?Git bash 使用可在注册表中调整的默认 Windows 控制台颜色。例如,为了提高可读性,可以通过应用如下所示的更改将深红色和深洋红色更改为较浅的版本:

Windows Registry Editor Version 5.00
; Default color scheme
; for Windows command prompt.

; Values stored as 00-BB-GG-RR
[HKEY_CURRENT_USER\Console]
; BLACK DGRAY
"ColorTable00"=dword:00000000
"ColorTable08"=dword:00808080
; BLUE LBLUE
"ColorTable01"=dword:00800000
"ColorTable09"=dword:00ff0000
; GREEN LGREEN
"ColorTable02"=dword:00008000
"ColorTable10"=dword:0000ff00
; CYAN LCYAN
"ColorTable03"=dword:00808000
"ColorTable11"=dword:00ffff00
; RED LRED --> To increase readability, use e.g. 000000aa for "ColorTable04"
"ColorTable04"=dword:00000080
"ColorTable12"=dword:000000ff
; MAGENTA LMAGENTA --> To increase readability, use e.g. 00aa00aa for "ColorTable05"
"ColorTable05"=dword:00800080
"ColorTable13"=dword:00ff00ff
; YELLOW LYELLOW
"ColorTable06"=dword:00008080
"ColorTable14"=dword:0000ffff
; LGRAY WHITE
"ColorTable07"=dword:00c0c0c0
"ColorTable15"=dword:00ffffff

回答by Glenn Werner

2017 UpdateOpen Gitbash and click the icon in the upper left corner and select "Options"

2017更新打开Gitbash,点击左上角的图标,选择“选项”

From the options menu you can configure transparency, foreground color (text), background color, and cursor color. Pretty straightforward and easy.

从选项菜单中,您可以配置透明度、前景色(文本)、背景色和光标颜色。非常简单明了。

回答by VonC

Since those color names are linked to ANSI escape codes(as I mentioned in a previous answer), you can try the approach described in this issue:

由于这些颜色名称与ANSI 转义码相关联(正如我在之前的回答中提到的),您可以尝试本期中描述的方法:

Just add these to your .bashrc

只需将这些添加到您的 .bashrc

echo -ne "\e]4;4;#007fff\a"  # 4;4 is Dark Blue #005FFF

(pick an rbg value which seems more readable to you for color blue, or choosing from this palette)

(为蓝色选择一个对您来说更易读的 rbg 值,或者从这个调色板中选择)

回答by J.M.I. MADISON

Windows10 + GitBash:Warning Message Samples

Windows10 + GitBash:警告消息示例



The following samples will print out a red background with white text.

以下示例将打印出带有白色文本红色背景

Original colors are RESTOREDafter the print.

打印后恢复原始颜色。



Echo One Line Message:

回显一行消息:

MSG="MY_WARNING_MESSAGE_TEXT" BG="41m" FG="1m"
echo -en "3[$FG3[$BG$MSG3[0m\n"


Block Of Colored Text with HARDCODED message:

带有硬编码消息的彩色文本块:

BG="41m" FG="1m"
HD_CAT_VAR=$(cat << 'HEREDOC_CAT_VAR_REGION'
+-------------------------------------+
|                                     |
|     HARD_CODED_WARNING_MESSAGE      |
|                                     |
+-------------------------------------+
HEREDOC_CAT_VAR_REGION
)
echo -en "3[$FG3[$BG$HD_CAT_VAR3[0m\n"


Block of Colored Text with VARIABLE message:

带有 VARIABLE 消息的彩色文本块:

VARIABLE_WARNING_MESSAGE="OH_NOOOOOO!"
BG="41m" FG="1m"
HD_CAT_VAR=$(cat << HEREDOC_CAT_VAR_REGION
+-------------------------------------+
|                                     |
+-------------------------------------+
      $VARIABLE_WARNING_MESSAGE        
+-------------------------------------+
|                                     |
+-------------------------------------+
HEREDOC_CAT_VAR_REGION
)
echo -en "3[$FG3[$BG$HD_CAT_VAR3[0m\n"

回答by Bigberg

To change the windows console color, you can use Microsoft's Colortool:

要更改 Windows 控制台颜色,您可以使用 Microsoft 的 Colortool:

The colortool will work with any .itermcolors scheme.

colortool 将适用于任何 .itermcolors 方案。

https://blogs.msdn.microsoft.com/commandline/2017/08/11/introducing-the-windows-console-colortool/

https://blogs.msdn.microsoft.com/commandline/2017/08/11/introducing-the-windows-console-colortool/

Github: https://github.com/Microsoft/console/tree/master/tools/ColorTool

Github:https: //github.com/Microsoft/console/tree/master/tools/ColorTool