Reputation: 527
I am trying to set up custom colors for git status, as described here
While using predefined color names works:
[color "status"]
changed = yellow normal
using ANSI 256 color codes does not work:
[color "status"]
changed = "\033[38;5;214m" normal
I get an error:
fatal: bad config line 31 in file .gitconfig
I have tries using hex code, but that does not work either:
[color "status"]
changed = "#d70000" normal
I suspect the #
is interpreted as comment.
My git version is 2.20.1
Upvotes: 2
Views: 605
Reputation: 76489
If you want to use a 256-color code, you can do so with a normal number from 0 to 255. For example, in my .gitconfig
, there's these entries:
[color.diff]
new = 34
old = 203
You don't want to place an actual escape sequence into the file. Git knows how to take a numeric value and issue the proper ANSI escape sequnce. It does not, however, handle terminal-specific capabilities or use terminfo, so if your terminal doesn't support the standard ANSI sequences, then it won't work with Git.
Upvotes: 4
Reputation: 9523
From documentation (https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration):
You can set the color to any of the following values:
normal
,black
,red
,green
,yellow
,blue
,magenta
,cyan
, orwhite
. If you want an attribute like bold in the previous example, you can choose frombold
,dim
,ul
(underline),blink
, andreverse
(swap foreground and background).
So you have just a limited selection, OTOH it is good to have few colours on terminals (you can change each colour, e.g. solarize the palette, but for usability, less is better).
Note: using names is good: git will find and "outsource" the generation of correct escape sequence according to the terminal of choice.
Upvotes: -3
Reputation: 1324268
First, "" would not be supported in config
changed = #d70000 normal
Second, your terminal has to support it. In a CMD on Windows, for instance, that would not work.
I did not manage to include Ansi escape code though.
Upvotes: 2