First of all, I know similar questions have been answered, some of them have even been marked as duplicate. I have read their answers, and while they've given me some insight regarding my problem, I still can't figure out how to fix my PS1. I've also tried reading a bit about UNIX quotes, but that didn't solve my problem either.
Now, into the actual problem: I've had a custom PS1 for a while now, that always worked just fine. It's this one:
SEPARATOR="$WHITEBOLD-"
USER_AND_DOMAIN="$GREENBOLD[$GRAY\u$WHITEBOLD@$GRAY\h$GREENBOLD]"
WORKING_DIR="$GREENBOLD[$YELLOW\w$GREENBOLD]"
export PS1="$USER_AND_DOMAIN$SEPARATOR$WORKING_DIR $WHITEBOLD\t\n$RED>$WHITE "
However, I felt the need to add my current git branch to it, and found a couple solutions in the web. One of them really caught my interest, because it would change the branch name's color depending on whether my working directory was dirty or not. I then started trying to adapt it to my currently existing customization, and at the moment it looks like this:
SEPARATOR="$WHITEBOLD-"
USER_AND_DOMAIN="$GREENBOLD[$GRAY\u$WHITEBOLD@$GRAY\h$GREENBOLD]"
WORKING_DIR="$GREENBOLD[$YELLOW\w$GREENBOLD]"
GIT_BRANCH="$(git branch &>/dev/null;\
if [ $? -eq 0 ]; then \
echo "$(echo `git status` | grep 'not staged for commit' > /dev/null 2>&1; \
if [ "$?" -eq "0" ]; then \
# Changes to working tree
echo "$SEPARATOR$GREENBOLD[$RED\$(__git_ps1 "%s")$GREENBOLD]"; \
else \
# Clean repository - nothing to commit
echo "$SEPARATOR$GREENBOLD[$GREEN\$(__git_ps1 "%s")$GREENBOLD]"; \
fi)"; \
fi)"
export PS1="$USER_AND_DOMAIN$SEPARATOR$WORKING_DIR$GIT_BRANCH $WHITEBOLD\t\n$RED>$WHITE "
However, although it does change the branch name when I navigate to another branch, the branch color doesn't change automatically - it only does so if I re-source the script (it's a separate script under ~/.ps1_setup
, which is called within ~/.bashrc
) manually. By what I've read, it has to do with the use of single and double quotes, but most examples I've seen are quite simpler than this code, and I've been trying to fiddle with it for the last 2h, getting different results every time, but most of them are messed up prints of the tags in the escaped format.
Again, I know this is somewhat related to stuff that has been asked and answered before, but the answers given were not enough for me to solve this, so I apologize for asking 'again'. Thanks for any help, good folks! :)