I have limited experience with BASH and I am looking for some guidance about how to proceed so please bear with me.
I am trying to change the command prompt when I am inside a git repo, which I can do using this post I found on google, but I also would like to add color depending on the current state of the repo (clean, untracked files, modified files).
Currently I have this at the end of my .bashrc file:
parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1]/'
}
modified () {
git status 2> /dev/null | grep -q modified
}
untracked () {
git status 2> /dev/null | grep -q Untracked
}
clean () {
git status 2> /dev/null | grep -q clean
}
NO_COLOR="\[\033[0m\]"
GREEN="\[\033[0;32m\]"
YELLOW="\[\033[0;33m\]"
RED="\[\033[0;31m\]"
set_color () {
if untracked ; then
echo $RED
elif modified ; then
echo $YELLOW
elif clean ; then
echo $GREEN
else
echo $NO_COLOR
fi
}
PS1="\u:\w\$(set_color)\$(parse_git_branch)$NO_COLOR> "
The command prompt changes but does not change the color like I think it should.
Here is what I get instead:
outside git repo arod:~\[\033[0m\]>
inside a git repo arod:~/tos\[\033[0;32m\][dev]>
I am unsure how to get the color to evaluate I think, just looking for some guidance from someone with more BASH experience than I have.