24

I've successfully played around with some of the color settings in the Git Bash on Windows - I'm able to set a few things, like the colors of the local, the current and remote branches in my .gitconfig file:

[color "branch"]
current = cyan bold
local = cyan 
remote = red

But what I haven't managed to change are the colors of the prompt - the username@machine at the beginning of the line (in the yellow rectangle in my screenshot), and the project and branch I'm currently on (purple rectangle).

enter image description here

Is there a way to influence those, too? Which .gitconfig settings do I need to set to change those colors?

user229044
  • 232,980
  • 40
  • 330
  • 338
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Do you have a `~/.bashrc` or `~/.bash_profile`? What happens if you say `PS1=""`? – bitmask May 07 '12 at 12:04
  • I have a `.bashrc` file with a few bash alias - but no `bash_profile` – marc_s May 07 '12 at 12:08
  • @bitmask: adding a `SET PS1=""` line to `.bashrc` doesn't appear to do anything at all ... – marc_s May 07 '12 at 12:18
  • In normal `bash` you can control the prompt solely by specifying it in the `PS1` variable, so if you override it `""` from the command line, the prompt should disappear (confirming that you can design it, by changing your `PS1` environment variable). – bitmask May 07 '12 at 12:35
  • Just ask google for `PS1 bash`. It gives you tons of tutorials and alike. – bitmask May 07 '12 at 13:53

1 Answers1

15

In your .bashrc you can set your prompt using the PS1 variable (which is likely set to a global value in /etc/profile or another file in /etc which may be distribution dependent).

Here's an example:

PS1='\[\033[1;36m\]\u@\h:\[\033[0m\]\[\033[1;34m\]\w\[\033[0m\] \[\033[1;32m\]$(__git_ps1)\[\033[0m\]\$ '

In order for the command substitution to work, you need shopt -s promptvars which is the default.

This will output the user and hostname in cyan, the current directory in blue and the git branch in green on terminals that work with TERM=xterm-color.

See man 5 terminfo and man tput for more information about terminal controls.

Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
  • 2
    Great ! Thanks - you learn something new every day here on Stackoverflow! – marc_s May 07 '12 at 13:58
  • I'm not sure of the exact rules in all situations (interactive or not) but you may need to create a `.bash_profile` which then calls the `.bashrc` with this line: `[[ -f ~/.bashrc ]] && . ~/.bashrc` – NeilG Nov 18 '22 at 10:30