Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A parameter cannot be found that matches parameter name 'TokenKind'

I have beautified my Powershell according to this blog, but the Operator and Parameter are grey as follows:

enter image description here enter image description here

So I change their colors by Set-PSReadlineOption:

Set-PSReadlineOption -TokenKind Operator -ForegroundColor Yellow

but get the following errors:

Set-PSReadLineOption : A parameter cannot be found that matches parameter name 'TokenKind'

所在位置 行:1 字符: 22

  • Set-PSReadlineOption -TokenKind Operator -ForegroundColor Yellow
    • CategoryInfo : InvalidArgument: (:) [Set-PSReadLineOption],ParameterBindingException
    • FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.SetPSReadLineOption

But the help documents of Set-PSReadlineOption shows that it has a TokenKind parameter which in turn can have Operator as its parameter.

I'm confused why this error happens.

My powershell version is

enter image description here

Thanks for any suggestions!

like image 968
Z-Y.L Avatar asked Sep 13 '18 08:09

Z-Y.L


1 Answers

They made a breaking change PSReadline V2, read about it here: https://github.com/lzybkr/PSReadLine/issues/738

So instead of

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

You would do something like

$colors = @{}
$colors['String'] = [System.ConsoleColor]::Magenta
$colors['Variable'] = [System.ConsoleColor]::Cyan
Set-PSReadLineOption -Colors $colors

I think there is a way to specify foreground/background color in the hashtable as well, but haven't figured out yet.

Read the Set-PSReadLineOption doc here.

like image 85
user3234429 Avatar answered Oct 22 '22 19:10

user3234429