Как получить доступ к значениям Solarized в скрипте bash

1119
PhiloEpisteme

Я пытаюсь сделать мои bash PS1быстрые цвета в соответствии с темой Solarized . Я установил и работаю с соляризациейiTerm2, но до сих пор не удалось создать настраиваемое приглашение PS1, соответствующее теме.

Я пытался использовать такие значения, как следующие для голубого, но в итоге я получил либо нет цвета, либо неправильный цвет. \033[0;37m

Я получил значения выше по следующей ссылке. https://github.com/altercation/solarized/tree/master/iterm2-colors-solarized

0

1 ответ на вопрос

1
theoden

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.