.bashrc, I use ANSI terminal color codes to colorize various bits. It looks like this:
git_branch are bash functions that output stuff on stdout.
Now, to make it easier to read and modify, I'd like to store the color codes in variables and refer to them, instead of embedding them directly into
PS1. So I have a bunch of variables like this:
GREEN="\[\033[32m\]" YELLOW="\[\033[33m\]" RESET="\[\033[0m\]"
I'd like to be able to write something like:
But this doesn't work -- the color codes show up in the prompt, like they're escaped. The colors work correctly if I use double quotes instead for
PS1, but then the prompt only changes when I do
I've tried other things I've seen people do -- using
printf, using single quotes for the colors, putting the
PS1 instead of the color variable, but nothing seems to work.
How can I use variables for the color codes?