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?
You can specify the color of text by using the ForegroundColor parameter, and you can specify the background color by using the BackgroundColor parameter.
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).
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.
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'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With