This question is very similar to this one: Colored PS1 string
But I still don't understand completely.
So say I have this function
function getjobs {
echo $(jobs | wc -l)
}
And my PS1 is this
PS1="\u@\h: [jobs "
PS1="$PS1\$(if [[ $(getjobs) == 0 ]] ; then
echo $(color $green);
else
echo $(color $red);
fi)"
Now this only gets evaluated when .bashrc is loaded for the first time but what I want to have happen is this if statement evaluated every time a new prompt appears.
How can I do this?
EDIT: the color
function returns escape sequences for those colors.