Reputation: 755421
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).
Is there a way to influence those, too? Which .gitconfig
settings do I need to set to change those colors?
Upvotes: 24
Views: 22635
Reputation: 3446
I recently discovered, that in .bashrc
file located in your user folder, there is part of script:
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
that when uncommented, will add to PS1
variable the bit of colors:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
otherwise, plain prompt is set.
In general, I'd suggest to see what's happening in this script, as it's a final configuration step in launching Git Bash.
And extra tip, to apply changes without opening and closing the terminal, you can:
source ~/.bashrc
#same as
. ~/.bashrc
Upvotes: 0
Reputation: 360683
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.
Upvotes: 15