我正在尝试为我的 git 配置添加一些颜色,我想知道终端上可用的颜色名称。
许多在线参考资料经常谈论我的系统上未定义的颜色名称,因此我只需要一种方法来查看我的默认选项是什么。
gol*_*cks 28
Many online references often talk about color names that are not defined on my system
Those probably are defined, but they are X11 colors; once upon a time you could find them in /lib[64]/X11/rgb.txt. In any case, this is a mapping of strings (e.g., dimgray) to 24-bit RGB colors (e.g. 0xff8800 or #ff8800, which would be orange). A 24-bit space is ~16 million colors, obviously X11 does not give them all names (CSS 3 uses X11 names, BTW).
The 24-bit space is used by your GUI; transparency is implemented by increasing this to a 32-bit space. However, git isn't a GUI (G = graphical) tool, it's a TUI (T = terminal) tool, and it is limited to the colors available on a normal terminal.
I would like a solution that works for all distros, but primarily Debian
If you want this to be properly portable, you should rely only on the eight standard ANSI colors:
A little disappointing next to the X11 list, but better than nothing at all! These also have a "bold" or "bright" version that is standard, making 16 colors, which you may be able to specify as, e.g., "brightyellow" (or conversely, "darkyellow").
Most GUI terminals1 have 256 color support and some terminal apps can exploit this. To test, you first need to set the $TERM variable appropriately:
export $TERM=xterm-256color
Run Code Online (Sandbox Code Playgroud)
Your terminal emulator may also have a configuration option for this. Colors under the xterm 256 color protocol are indexed:

索引号位于左下角。请注意,此图表底部的集合 (0-15) 是 16 种基本(明暗)ANSI 颜色。要在标准下引用这些颜色之一,请使用color+ 索引号,例如。color40.
1.“GUI终端”是在GUI上下文中运行的终端模拟器,例如xterm、GNOME终端等。但是,这不会使在GUI终端中运行的TUI应用程序(例如git)成为GUI应用程序。 它们仍然是 TUI 应用程序,并受该上下文的约束。