Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell hyphen argument color

I want to change the color of the -a, --All arguments in Powershell. I have changed the string and command colors of my in Powershell like this.

Set-PSReadlineOption -TokenKind String -ForegroundColor Cyan
Set-PSReadlineOption -TokenKind Command -ForegroundColor Magenta

I cannot find how to change the hyphen arguments color.

Is it under Set-PSReadlineOption or somewhere else?

like image 581
Mullenb Avatar asked Jul 07 '17 20:07

Mullenb


People also ask

How do I change the output color in PowerShell?

You can specify the color of text by using the ForegroundColor parameter, and you can specify the background color by using the BackgroundColor parameter.

How do I change the text color in PowerShell ISE?

To change the color of the ISE Editor, we need to use $psISE cmdlet which is only available for the ISE editor. Now in the ISE editor, we have many colors some are visible (ScriptPane color, Console Color, etc) and some appear while executing a script (Error, Warning, Verbose).

What is hyphen in PowerShell?

The topic name is the value of the Name parameter. In a PowerShell command, parameter names always begin with a hyphen. The hyphen tells PowerShell that the item in the command is a parameter name. Parameters can be mandatory or optional.


1 Answers

You're looking for the Parameter token kind:

Set-PSReadlineOption -TokenKind Parameter -ForegroundColor Red

The above will color parameter tokens (like -a) red, but not bare string tokens prefixed with -- (like --All), since they're technically not considered parameter tokens by the parser.


As Rabeez Riaz notes, in PSReadLine 2.0 the syntax is slightly different:

Set-PSReadLineOption -Colors @{ Parameter = 'Red' }

The new syntax allows you to set multiple token colors simultaneously:

Set-PSReadLineOption -Colors @{
  Parameter  = 'Red'
  String     = 'Cyan'
  Command    = 'Green'
}
like image 138
Mathias R. Jessen Avatar answered Sep 25 '22 06:09

Mathias R. Jessen