I know there are ways to use ANSI color names in Zsh (such as red), but Zsh supports 256 colors by number. I'm curious if there's any way to refer to the non-ANSI colors by a name? (Without just sticking them in a variable)
Shell – Is it possible to use named colors in Zsh beyond ANSI names
colorsshellzsh
Best Answer
The first 16 colors have been standard for a long time (and have mostly standard hues). 256 colors are a more recent extension defined by xterm and compatible terminals. The xterm documentation has this to say about colors 16–255:
The colors can be changed from within the terminal; see the
ctlseqs
file. For exampleprint '\e]4;42;taupe\a'
changes color 42 to be taupe (the color names are available in/etc/X11/rgb.txt
or some other distribution-dependent location).If you're content to assume that the colors above 16 have their default values, you could extend the
$color
array with names fromrgb.txt
. You'll need to do a bit of arithmetic to find the closest approximation of 8-bit colors in lg(6)-bit colors.