I'm trying to set up my prompt to conditionally display whether I am in a git repo, and if so, to display the branch. And I want it color coded, so I have it use some color escape sequences to make it look nice. When I go to print it though, I just get this:
alex@alexslaptop:~/gittest \e[0;35m(git:\e[0;32mmaster\e[0;35m) $
What I expect to see is something like this (except colorized)
alex@alexslaptop:~/gittest (git:master) $
I've narrowed it down to the fact that I have a function in my PS1 variable that I have to run every time, so I have something like this:
PS1=""
PS1+="${COLOR_LIGHT_CYAN}\u"
PS1+="${COLOR_WHITE}@"
PS1+="${COLOR_LIGHT_CYAN}\H"
PS1+="${COLOR_WHITE}:"
PS1+="${COLOR_LIGHT_BLUE}\w "
PS1+="\$(vcs_prompt)" #Notice the backslash before the $
PS1+="${COLOR_NC}\$ "
export PS1
If I remove the backslash on the annotated line, it works, but only once and never updates. If I add it in, it updates, but displays the escape sequences for the colors.
Since vcs_prompt is a nontrivial function I'll give a simplified example that displays the same behavior:
export COLOR_BLUE='\e[0;34m'
export COLOR_RED='\e[0;31m'
function blue {
echo "${COLOR_BLUE}blue"
}
export PS1="${COLOR_RED}red \$(blue)"
I would expect it to display
red blue
with the words being colored appropriately. Instead I get:
red \e[0;34mblue
Is there a way to get this to behave how I want?