Search code examples
gitcommand-promptbash

PS1 line with Git current branch and colors


Here is my current PS1:

export PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '

How can I display the current branch in a different color?


Solution

  • You can wrap the part that you want in colour with the following:

    \e[0;32m - sets colour (in this case, to green)

    \e[m - sets colour back to the default

    For example, this sets the prompt to the last token of the current path, in green, followed by $ in the default colour:

    export PS1='\e[0;32m\w\e[m $'
    

    Other colours are available too. Have a look at this article under colorization for a comprehensive list of alternatives.