1

In my .bash_profile I have a parse_git_branch function from the internet, and a PS1 to color some of my output.

If possible, I would like to make my git branch name colored red, instead of white.

I tired changing a few variables, but with no luck. I would like (master) to be red, if possible.

enter image description here

  • 1
    OK; I gave you one free fish. Now it’s time for you to learn to fish. P.S. Please post text as text rather than screenshots. – G-Man Says 'Reinstate Monica' Sep 21 '18 at 4:20
  • @G-Man I think I found the solution, but I don't have my laptop with me at the moment to try it. I think by changing \w[033[m]\ to \w[033[31m]\ would give the desired output. I thought I had tried something like that and it didn't work, but I don't remember. I tried a few things before making a question. – DrZoo Sep 21 '18 at 14:55
  • That sounds right. – G-Man Says 'Reinstate Monica' Sep 21 '18 at 15:02
  • @G-Man that did the trick. Thanks for the link you shared. – DrZoo Sep 22 '18 at 4:45
1

You can use color codes for this.

PS1='\e[31TextInRed\e[0m'

Where \e[31 will render everything on the terminal in red color, 31 being the color code for red and \e[0m resets the color back to normal so that your terminal isn't messed up(i.e all the text would be colored in red).

Read more about color codes here

1

I was able to get the git branch to print out in red by changing

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[93m\]\w\[\033[m\]\$(parse_git_branch)\[\033[00m\] \n$ "

to

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[93m\]\w\[\033[31m\]\$(parse_git_branch)\[\033[00m\] \n$ "

To highlight the specific change was using [31m\]\$(parse_git_branch) instead of [m\]\$(parse_git_branch)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.