How to access Solarized color values within bash script

0

I'm trying to make my bash PS1 prompt colors according to the Solarized theme. I have solarized installed and working for iTerm2, but so far have been unsuccessful in creating a custom PS1 prompt that matches the theme.

I have tried using values such as the following for cyan, but I end up getting either no color or the wrong color. \033[0;37m

I obtained the values above from the following link. https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized

PhiloEpisteme

Posted 2015-08-03T23:01:29.183

Reputation: 111

Answers

1

If what you're asking is ANSI escape sequences, here are a few tips:

0 Black
1 Red
2 Green
3 Yellow/Brown
4 Blue
5 Pink
6 Cyan
7 White/Gray

Each of them is applied to foreground, or background color.

3_  sets grim    foreground color
9_  sets intense foreground color
4_  sets grim    background color
10_ sets intense background color
# 3-4, 9-10 and a code for a color.

For example, by doing printf "\033[1;44;97m" you make your background 44 (grim blue) foreground 97 (intense white).

There are other useful color codes you should also use:

0 reset all colors
1 bold
3 italics
4 underline
5 blink
7 inverse

To make it more comfortable to work with that, you can make a set of aliases like fiblue fred bblack etc. You may also add the following function to your bashrc:

ansi() {
    printf "\033[$1"
}

So that instead of writing \033[1;35m you do ansi '1;35m', and writing color aliases with that function is more comfortable.

You should also take a note that setting a background color resets already set foreground color, so you should use \033[misc;background;foregroundm.

This way, you can paint any PS1 you like. Here's an example:

PS1="\033[0;1;36m\u\033[0;1m:\033[1;103;30m\t\033[0m \033[1;92m\$\033[0m \r"

Also have a look at bash_it.

Hope I answered what you asked.

theoden8

Posted 2015-08-03T23:01:29.183

Reputation: 644