Stupid Saturday morning code snippet.
I've found online a snippet code that allows me to get the current branch in PS1, wonderful! but...
I'd like to have different colors based on the branch.
I said, "You don't know anything about bash but should be really easy! just an if..."
After 6 hours of tests, here we go.
Could someone explain me where is the problem?
I know that there are many projects on GitHub that do this job for me, but I would like just to understand.
Thank you so much
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
set_ps1_git_branch_color(){
BRANCH=$(parse_git_branch)
if [ $BRANCH == "(master)" ]; then
echo -e "\W\[\033[35m\] $BRANCH \[\033[00m\]"
fi
if [ $BRANCH == "(test)" ]; then
echo -e "\W\[\033[32m\] $BRANCH \[\033[00m\]"
fi
}
export PS1="\u@\h $(set_ps1_git_branch_color) $ "
It works just if I execute source ~/.bash_profile after each git operations ( like checkout ).
But the original snippet parse_git_branch() is able to change the branch name without the source command.
so...what I'm missing here? :(

=is enough in bash for conditionals and is the right syntax