找不到与参数名称匹配的参数 'TokenKind'

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

我已经按照this blog美化了我的Powershell,但是OperatorParameter是灰色的如下:

所以我通过 Set-PSReadlineOption 改变它们的颜色:

Set-PSReadlineOption -TokenKind Operator -ForegroundColor Yellow

但出现以下错误:

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

但是 Set-PSReadlineOptionhelp 文档表明它有一个 TokenKind 参数,而这个参数又可以有 Operator 作为它的参数。

我很困惑为什么会出现这个错误。

我的 powershell 版本是

感谢您的任何建议!

他们对 PSReadline V2 进行了重大更改,请在此处阅读:https://github.com/lzybkr/PSReadLine/issues/738

所以不用

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

你会做类似的事情

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

我认为也有一种方法可以在哈希表中指定 foreground/background 颜色,但还没有想出。

阅读 Set-PSReadLineOption 文档 here