【发布时间】:2019-01-22 08:04:07
【问题描述】:
这是我的 powershell 脚本中的哈希表(使用 Get-PSReadlineOption 提取的数据):
$theme = @{}
$theme["CommentForegroundColor"] = "DarkGreen"
$theme["CommentBackgroundColor"] = "Black"
$theme["KeywordForegroundColor"] = "Green"
$theme["KeywordBackgroundColor"] = "Black"
我正在尝试使用 Set-PSReadlineOption 命令设置 powershell 主题颜色:
foreach ($colorTokenKey in $theme.keys) {
$c=$theme[$colorTokenKey]
echo "$colorTokenKey will be set to $c"
$colorTokenArgs = $colorTokenKey.Replace("ForegroundColor"," -ForegroundColor")
$colorTokenArgs = $colorTokenArgs.Replace("BackgroundColor"," -BackgroundColor")
$colorTokenArgs = $colorTokenArgs.Split(" ")
$tokenKind = $colorTokenArgs[0]
$tokenForegroundOrBackground = $colorTokenArgs[1]
$params = "-TokenKind $tokenKind $tokenForegroundOrBackground $c"
echo $params
& Set-PSReadlineOption $params
}
但是当我运行它时,我得到了
CommandBackgroundColor 将设置为白色 -TokenKind 命令 -BackgroundColor 白色 Set-PSReadlineOption:无法绑定参数“TokenKind”。无法转换价值“-Tok enKind Command -BackgroundColor White" 输入 "Microsoft.PowerShell.TokenClassifica 化”。错误:“无法匹配标识符名称 -TokenKind 命令 -BackgroundCol 或 White 为有效的枚举数名称。指定以下枚举器名称之一 再试一次: 无、注释、关键字、字符串、运算符、变量、命令、参数、类型、数字 , 成员” 在 C:\Users\...\PowerShellColors.ps1:88 char:28 + & 设置-PSReadlineOption $params我做错了什么?
【问题讨论】:
标签: powershell arguments