8

我已经根据这个博客美化了我的 Powershell ,但是OperatorParameter是灰色的,如下所示:

在此处输入图像描述 在此处输入图像描述

所以我通过以下方式更改它们的颜色Set-PSReadlineOption

Set-PSReadlineOption -TokenKind Operator -ForegroundColor Yellow

但得到以下错误:

Set-PSReadLineOption :找不到与参数名称 'TokenKind' 匹配的参数。</p>

所在位置 行:1 字符: 22

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

但是 的帮助文档Set-PSReadlineOption显示它有一个TokenKind参数,该参数又可以Operator作为它的参数。

我很困惑为什么会发生这个错误。

我的powershell版本是

在此处输入图像描述

感谢您的任何建议!

4

1 回答 1

16

他们对 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

我认为还有一种方法可以在哈希表中指定前景色/背景色,但还没有弄清楚。

在此处阅读 Set-PSReadLineOption 文档。

于 2018-10-04T16:32:03.463 回答