PowerShell: Change the Color of the Prompt

PowerShell opens up in a soothing white-on-blue console by default. But, the prompt is displayed in the same color as the rest of the text. The color of the prompt can be changed by overriding the default Prompt method by writing a custom Prompt method and placing it in your profile script.

This is a simple Prompt method that sets the color of the prompt to yellow:

function Prompt
{
    $promptString = "PS " + $(Get-Location) + ">"
    Write-Host $promptString -NoNewline -ForegroundColor Yellow
    return " "
}

The above Prompt method is enough if the profile script is meant for the default PowerShell console only. If you are using a profile script that will be used by other PowerShell hosts (like PowerShell ISE for example), then maybe you do not want the prompt to be yellow in those hosts.

For such cases, this is a Prompt method that sets the color of the prompt to yellow only for the default PowerShell console and uses the default color for the other hosts:

function Prompt
{
    $promptString = "PS " + $(Get-Location) + ">"

    # Custom color for Windows console
    if ( $Host.Name -eq "ConsoleHost" )
    {
        Write-Host $promptString -NoNewline -ForegroundColor Yellow
    }
    # Default color for the rest
    else
    {
        Write-Host $promptString -NoNewline
    }

    return " "
}

Tried with: PowerShell 2.0

Console2: Change Text Color

Console2 is a Windows utility that can be used to host the Windows command shell (cmd.exe), PowerShell, Cygwin shells or any other shell. By default, it displays a black background and the text is displayed in a dull gray color.

The Settings dialog of Console2 does not really indicate where this text color comes from or how to change it. To change the default text color to pure white or any other color, open EditSettings dialog. In the Console Colors Map section, locate the gray color square (marked in the screenshot above) and change it to any color you want. The console text will be displayed in your chosen color.

Tried with: Console2 2.00.147

Vim: Set Color of ColorColumn

One or more guidelines can be added in Vim using the colorcolumn setting. Vim picks the color for this colorcolumn based on whether it is in GUI or non-GUI mode and on the background setting. If you are not happy with the color of the colorcolumn, it can be changed easily by setting the color of the ColorColumn highlighting group.

For non-GUI Vim running in the Windows command prompt, the color is set using the ctermbg argument to the ColorColumn highlighting group. For example, to set the colorcolumn to a light grey color try:

highlight ColorColumn ctermbg=7

The 16 color values that can be used with ctermbg argument can be seen by typing :help ctermbg

For GVim, the color is set using the guibg argument to the ColorColumn highlighting group. For example, to set the colorcolumn to a black color try:

highlight ColorColumn guibg=Black

To see the list of colors that can be used for the guibg argument, type :help guibg in GVim. A detailed chart of Vim color names can be seen here.

Tried with: Vim 7.3

Vim: Chart of Color Names

I prefer to set the colors in Vim using available named colors rather than RGB values. To make it easy to pick from among the named colors, here is a chart of all the color names available in Vim (see below). This was generated using the script from here.

Colors in the Windows Command Prompt

The main color settings of the Windows command prompt that can be changed are the background and text (foreground) color. There is also the equivalent popup background and text color, but that is rarely used.

Colors Dialog

The most common way to change the colors is to open the window menu (click the top left corner of window or press Alt+Space) and choose Properties and pick the Colors tab in the Properties dialog. There are 16 pre-defined colors available for the background and text. To set a custom RGB value as the background or text color, click on one of the pre-defined color squares and then set that square’s custom color by using the Selected Color Values section in the top right corner.

Color Command

Sometimes, you might be stuck at the command prompt of a friend who has set colors that are making your eyes bleed! :-D Use the color command from the command-line to change the color for that session temporarily and save your eyes! For example to switch to a black-on-white color setting immediately, type color F0 at the prompt.

The color command accepts one value of type XY, where X and Y are hexadecimal digits. X represents the background and Y the text color. Each of those values is one of the 16 pre-defined (or customized) colors set for that command-prompt using the Colors dialog (as described above). If the same value is provided for both background and text (00 for example), it is ignored.

After finishing your work at the friend’s command prompt, you can switch back to his painful colors by typing color (with no arguments).

LaTeX: Color Text

Adding color to text in LaTeX is super easy!

Include the color package:

\usepackage{color}

Specify the color and the text you want colored to the textcolor command wherever needed:

\textcolor{red}{This is colored in red!}

To see other predefined color names go here.