Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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)

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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:

These specify the colors for the 256-color extension. The default resource values are for colors 16 through 231 to make a 6x6x6 color cube, and colors 232 through 255 to make a grayscale ramp.

The colors can be changed from within the terminal; see the ctlseqs file. For example print '\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 from rgb.txt. You'll need to do a bit of arithmetic to find the closest approximation of 8-bit colors in lg(6)-bit colors.

share|improve this answer
1  
this sounds like a PITA, you'd think someone would just do it so it doesn't have to be done on an individual system level. –  xenoterracide Sep 2 '10 at 14:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.