Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the color of string values I type?

In my job I have recently begun using Powershell quite frequently. To facilitate using it, I am attempting to customize the command prompt colors to my liking, but I have run into a snag when attempting to customize the color of quoted string values. Given how PS is a text based interface, this statement may not mean that much, so please refer to this

Picture with the offending(ly?) colored text surrounded with a yellow box

Apparently I can't embed images yet, so you'll have to click the link. Anyway, this text is extremely difficult for me to read, and I am attempting to switch it over to something with more contrast, but I can't find a setting for it.

I've looked at the following options already:

  1. Setting these colors in the UI (right-click context menu), but that only allows setting default foreground and background
  2. Setting the color utilizing $host.UI.RawUI, but this also only allows setting the default foreground and background
  3. Setting the color using $host.PrivateData, but while this provides more options, it doesn't seem to have options for setting the more context sensitive items like the quoted text or even the variable you can see in the image.

My fallback plan is to use PowerShell ISE if I must (it allows me to customize this), but I would prefer to have a lighter weight command prompt available if possible.

Has anyone figured out how to change this?

I'm using PowerShell v5 on Windows 10.

like image 775
jfc Avatar asked Apr 28 '16 09:04

jfc


1 Answers

PowerShell 5.0 ships with PSReadLine, a module that enhances the editing experience in the console by adding syntax highlight coloring among other things.

You can change the color of string tokens with Set-PSReadLineOption, for example:

Set-PSReadlineOption -TokenKind String -ForegroundColor Cyan

enter image description here


For PSReadLine version 2.0 and up, use the -Colors parameter and supply a dictionary of (optional) token color overrides to Set-PSReadLineOption:

Set-PSReadLineOption -Colors @{ String = 'Cyan' }
like image 104
Mathias R. Jessen Avatar answered Oct 08 '22 19:10

Mathias R. Jessen