Friday, June 14, 2013

Changing OpenRC colors to use Solarized

So, after switching my terminals to use the solarized color scheme, I was dismayed to discover that alot of apps don't like it when you change the ANSI colors.

OpenRC commands are no exception: rc-status, rc-config, and rc-service all tried to use the bold colors which have been reassigned, so the output is downright ugly.

I just went sifting through the OpenRC sources, and discovered a little gem: EINFO_COLOR is an environment variable that does more than turn color on or off. No, that little sucker allows you to redefine which ANSI colors it will use for output.

Here's what I do to make it use solarized. I put the following line in /etc/bash/bashrc (because everything is solarized, not just my user):

export EINFO_COLOR="good=2;0:bad=1;0:warn=1;1:hilite=7;1:"

This sets my colors to:
  • good is green
  • bad is red
  • warn is orange
  • hilite is base3
So, EINFO_COLOR lets you change the colors (all lower case): good, warn, bad, hilite, and bracket. You can't change the normal text color.

Each of the colors is a pair of two numbers

  • The first number is the ANSI Color (0-7)
  • followed by a semicolon (;)
  • followed by whether or not it should use the "bold" ANSI Color (0 is normal, 1 is "bold")
  • followed, by a colon (:) which serves to 'end' the number and separate the variables in the string
So that means that Solarized colors would be specified like this:


SOLARIZED HEX     16/8 TERMCOL   EINFO_COLOR
--------- ------- ---- -------   -----------
base03    #002b36  8/4 brblack   0;1:       
base02    #073642  0/4 black     0;0:       
base01    #586e75 10/7 brgreen   2;1:       
base00    #657b83 11/7 bryellow  3;1:       
base0     #839496 12/6 brblue    4;1:       
base1     #93a1a1 14/4 brcyan    6;1:       
base2     #eee8d5  7/7 white     7;0:       
base3     #fdf6e3 15/7 brwhite   7;1:       
yellow    #b58900  3/3 yellow    3;0:       
orange    #cb4b16  9/3 brred     1;1:       
red       #dc322f  1/1 red       1;0:       
magenta   #d33682  5/5 magenta   5;0:       
violet    #6c71c4 13/5 brmagenta 5;1:       
blue      #268bd2  4/4 blue      4;0:       
cyan      #2aa198  6/6 cyan      6;0:       
green     #859900  2/2 green     2;0: