[英]How to change RGB colors in Git Bash for windows?
I'm using the Git Bash in Windows and for the purposes of my custom git log
format, I'd like to modify the terminal's exact RGB color values so I can fine-tune the color outputs. 我在Windows中使用Git Bash,为了我的自定义
git log
格式,我想修改终端的确切RGB颜色值,以便我可以微调颜色输出。 My git log format is as follows in my global .gitconfig
: 我的git日志格式在我的全局
.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. 我想在Git Bash中定义RGB值实际上映射到'蓝色',例如。 Any idea how I can do this?
知道我怎么能这样做吗? Step by step instructions would be wonderful.
一步一步的说明会很精彩。 Thanks in advance.
提前致谢。
I setup my .bashrc and it isn't working for some reason. 我设置我的.bashrc并且由于某种原因它不起作用。 Colors aren't changing :-(. Here is a script I ran to see colors: http://pastebin.com/9EsYmGCj and the result: http://i.imgur.com/1dJ3o1a.png
颜色没有变化:-(。这是我跑来看色彩的脚本: http : //pastebin.com/9EsYmGCj和结果: http : //i.imgur.com/1dJ3o1a.png
This works for me to change the text colors used by Git Bash on Windows 7: 这适用于我在Windows 7上更改Git Bash使用的文本颜色:
The changes made in this way are permanent but only valid for the shortcut you have used to start Git Bash. 以这种方式进行的更改是永久性的,但仅对您用于启动Git Bash的快捷方式有效。 If you create a new shortcut you are back to the original colors.
如果您创建新的快捷方式,则会返回原始颜色。
If you are using the git-bash command prompt check if you have the file: %USERPROFILE%\\.minttyrc 如果您使用git-bash命令提示符,请检查您是否有以下文件:%USERPROFILE%\\。minttyrc
In that file you can fine tune the RGB values of the console colors in this way: 在该文件中,您可以通过以下方式微调控制台颜色的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
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
When using MSYSGIT, Git Bash runs in the Windows Command Prompt. 使用MSYSGIT时,Git Bash在Windows命令提示符下运行。 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 .
由于Git Bash是一个始终运行的命令,因此您可以在命令提示符的属性中设置其颜色,而不是默认值 。
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.
诀窍似乎是在编辑后从输入框中跳出标签。
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值,对于蓝色 ,或者从此调色板中选择,对您来说似乎更具可读性)
Why so complicated? 为什么这么复杂? Git bash uses the default Windows console colors which may be tweaked in the registry.
Git bash使用可在注册表中调整的默认Windows控制台颜色。 Eg to increase readability, one can change the dark red and the dark magenta to a lighter version by applying the changes as indicated below:
例如,为了提高可读性,可以通过应用如下所示的更改将深红色和深色洋红色更改为更轻的版本:
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
2017 Update Open 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.
非常简单易行。
Windows10 + GitBash: Warning Message Samples Windows10 + GitBash:警告消息示例
The following samples will print out a red background with white text . 以下示例将打印出带有白色文本的红色背景 。
Original colors are RESTORED after the print. 打印后恢复原始颜色。
Echo One Line Message: 回声一线消息:
MSG="MY_WARNING_MESSAGE_TEXT" BG="41m" FG="1m"
echo -en "\033[$FG\033[$BG$MSG\033[0m\n"
Block Of Colored Text with HARDCODED message: 带有HARDCODED消息的彩色文本块:
BG="41m" FG="1m"
HD_CAT_VAR=$(cat << 'HEREDOC_CAT_VAR_REGION'
+-------------------------------------+
| |
| HARD_CODED_WARNING_MESSAGE |
| |
+-------------------------------------+
HEREDOC_CAT_VAR_REGION
)
echo -en "\033[$FG\033[$BG$HD_CAT_VAR\033[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 "\033[$FG\033[$BG$HD_CAT_VAR\033[0m\n"
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.