How to change RGB colors in Git Bash for windows?
Asked Answered
G

9

60

I'm using 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. My git log format is as follows in my 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.

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/9EsYmGCj and the result: https://i.sstatic.net/WP9am.png

Gualterio answered 20/1, 2014 at 20:8 Comment(3)
a wild guess: is the blue color too dark?Terrier
@KarolyHorvath Yes it is. By the way, I'm not sure why people are requesting to close. I have a perfectly legitimate question.Gualterio
Regarding ANSI escape sequences, this can probably help: tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.htmlHypethral
D
66

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

  • 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", UPDATE 2021: "Options..." (thanks AlexD!)
  • 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.

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.

Duad answered 11/8, 2015 at 14:31 Comment(6)
This is the best answer and should actually be marked as answer (if only it were possible) because it includes the instructions without going to another site.Brogan
Please note that the changes made using this method will be permanent only if you opened The Git CMD/bash in administrator mode. Once the changes are in effect, there is no need to open it in administrator modeEringo
I have switched this to the best answer based on upvotes and how thorough the instructions are.Gualterio
for me after I altered the color I wanted to, I clicked to original color to reset the "text color" to its original value and it copied the altered colored rgb values to the original text color values, arrggg! so I clicked canceled, did it all over again, and after I finished altering the color I wanted to change I clicked ok, then came back and re-select the original color box for text. pfeeww, all done now. thank you!Ruthanneruthe
And on the "latest and greatest git version 2.33.0.windows.1" (08/2021) they changed from "Properties" to ... "Options"Threshold
And on version 2.39.0, there is no "Colors" tab. :)Annulate
F
31

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:

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
Fascism answered 16/5, 2017 at 21:11 Comment(3)
I also used this tool to export minttyrc file. Best answer !Hyperthermia
works for me. The default red was really hard to see. Copied the line for Red. And restarted mingw64Foulup
@Fascism I don't have this file; does this come with the Git Bash as default?Utility
T
20

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
Theology answered 13/10, 2016 at 0:7 Comment(1)
Imho, the only valid answer in there. The selected one describes how to change colors in windows terminal window, not in command prompt itselfValvular
M
8

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:

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
Mell answered 26/3, 2018 at 5:29 Comment(0)
M
6

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.

For instructions on changing the terminal colors, see: 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.

Meneses answered 8/8, 2014 at 23:42 Comment(0)
G
4

Windows10 + GitBash: Warning Message Samples


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:

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_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"
Garofalo answered 25/7, 2018 at 22:46 Comment(0)
W
3

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:

Just add these to your .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)

Witchery answered 21/1, 2014 at 7:1 Comment(2)
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: pastebin.com/9EsYmGCj and the result: i.imgur.com/1dJ3o1a.pngGualterio
Seems like this might be working for cygwin but not for msysgit (as provided by Git for Windows installer).Gualterio
S
3

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

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

Supereminent answered 14/8, 2017 at 19:55 Comment(2)
It's great to see something that uses a configuration tool, rather than editing the values directly.Boomer
Indeed this is good, but for me the "store" button, which I can only assume is for saving the configuration, is greyed out. So I cannot create new color profiles this way, just modify the current terminal. So it is a bit useless.Cupidity
P
0

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

The colortool will work with any .itermcolors scheme.

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

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

Predictor answered 11/10, 2017 at 18:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.