I’ve been using Git for my open source projects recently and have been loving it. If you are like me and you like using the PowerShell prompt instead of the normal command prompt then you have to install posh-git. posh-git extends the PowerShell prompt to include information about the git repository and also makes remote operations simpler. After using git in this way I quickly noticed that the colors were not very readable. For example take a look at the screen shot below.

image

In the image above you can see that the text in dark red is difficult to read. This text comes from two different places. For the text relating to modified and untracked files, that is coming directly from git.exe and for the text after [master that is coming from posh-git. In order to make this easier to read we have to modify the color settings for both.

Modifying text color settings for git.exe

When using git.exe you can configure the color settings using git config. There are a bunch of color settings which you can control, which are all listed on the manpage for git config. In my case I want to update the color for modified files and untracked files, those can be configured with color.status.changed and color.status.untracked respectively. The color options that you have to pick from include:

  • normal
  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white

In my case I wanted the text for those settings to be the same color as the master text in the image above. In order to set the color you can use the syntax:

git config “foreground-color background-color attribute”

The attribute value can be any of these values; bold, dim, ul, blink and reverse.

In my case I executed the following command:

git config --global color.status.changed "cyan normal bold"
git config --global color.status.untracked "cyan normal bold"

Notice that I used the --global switch to indicate that I wanted the settings to be persisted in the global .gitconfig file instead of the one for the specific project that I was working on. So this got me to:

image

Almost there, now I need to modify the color for the summary provided by posh-git. A good resource for more info here is http://git-scm.com/book/ch7-1.html#Colors-in-Git.

Modifying text color for posh-git

posh-git stores all of it’s color settings in the $global:GitPromptSettings variable, you can see them declared in the GitPrompt.ps1 file. If you want to change the values for the colors you should not edit that file (that file might get updated later). Instead all you need to do is to override the value for the particular color after posh-git has been loaded. The best way to do this is to edit your PowerShell profile. This file is executed every time you open a PS prompt. You can find the location of this file by executing $profile in a PS prompt. In that file you should see a line initializing posh-git in my case it was:

. 'G:\Data\Development\OpenSource\posh-git\profile.example.ps1'

You should place your customizations after this statement. So in my case I wanted to change the summary text from dark red to yellow, so I added the following lines to my PS profile.

$global:GitPromptSettings.WorkingForegroundColor    = [ConsoleColor]::Yellow
$global:GitPromptSettings.UntrackedForegroundColor  = [ConsoleColor]::Yellow

I closed the PS window and opened a new one and now here is the result.

image

Now that’s better!

FYI if you are looking to install posh-git you can follow a simple walk through on Phil Haack’s blog at Better Git with PowerShell.

I’d like to thank Brad Wilson and Keith Dahlby for pointing me in the right direction regarding these settings.

 

Sayed Ibrahim Hashimi | @SayedIHashimi

My Github account


Comment Section


Comments are closed.