это хеш-таблица в моем скрипте powershell (данные извлекаются с использованием Get-PSReadlineOption ):
$theme = @{}
$theme["CommentForegroundColor"] = "DarkGreen"
$theme["CommentBackgroundColor"] = "Black"
$theme["KeywordForegroundColor"] = "Green"
$theme["KeywordBackgroundColor"] = "Black"
Я пытаюсь установить цвета темы powershell с помощью Set-PSReadlineOption команда:
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 will be set to White
-TokenKind Command -BackgroundColor White
Set-PSReadlineOption : Cannot bind parameter 'TokenKind'. Cannot convert value "-Tok
enKind Command -BackgroundColor White" to type "Microsoft.PowerShell.TokenClassifica
tion". Error: "Unable to match the identifier name -TokenKind Command -BackgroundCol
or White to a valid enumerator name. Specify one of the following enumerator names a
nd try again:
None, Comment, Keyword, String, Operator, Variable, Command, Parameter, Type, Number
, Member"
At C:\Users\...\PowerShellColors.ps1:88 char:28
+ & Set-PSReadlineOption $params
Что я делаю не так?