格式化选项卡参数完成 powershell
Formatting tab argument completion powershell
我在 PowerShell 3 中使用 TabExpansion2,当我用 Tab 键完成一个参数时,它会显示我想要但包含在我不想要的语法中的字符串。
例如,当我在 -binName
之后点击制表符时:
Use-Bin -binName @{Name=5.0}
我需要的是:
Use-Bin -binName 5.0
我正在使用这个脚本:https://www.powershellgallery.com/packages/PowerShellCookbook/1.3.6/Content/TabExpansion.ps1
使用这些调整后的选项:
$options["CustomArgumentCompleters"] = @{
"binName" = {Get-ChildItem -Path $global:TH_BinDir | Select-Object Name}
"dbName" = {Get-ChildItem -Path $global:TH_DBDir\RT5.7\ | Select-Object Name}
"patchSubDir" ={Get-ChildItem -Path $global:TH_BinDir\Patches\ | Select-Object Name}
"hmiSubDir" = {Get-ChildItem -Path $global:TH_HMIDir | Select-Object Name}
"moduleScript" = {Get-ChildItem -Path $global:TH_ModPaths | Select-Object Name}
"items" = {"bins", "databases", "modules"}
}
谢谢!
我不熟悉 tabexpansion,但您的问题是您 returning 具有 name
属性的对象。您只想 return 字符串。
$options["CustomArgumentCompleters"] = @{
"binName" = {Get-ChildItem -Path $global:TH_BinDir | Select-Object -ExpandProperty Name}
"dbName" = {Get-ChildItem -Path $global:TH_DBDir\RT5.7\ | Select-Object -ExpandProperty Name}
"patchSubDir" ={Get-ChildItem -Path $global:TH_BinDir\Patches\ | Select-Object -ExpandProperty Name}
"hmiSubDir" = {Get-ChildItem -Path $global:TH_HMIDir | Select-Object -ExpandProperty Name}
"moduleScript" = {Get-ChildItem -Path $global:TH_ModPaths | Select-Object -ExpandProperty Name}
"items" = {"bins", "databases", "modules"}
}
由于您使用的是 3.0,这会更简洁并完成同样的事情。
$options["CustomArgumentCompleters"] = @{
"binName" = {(Get-ChildItem -Path $global:TH_BinDir).Name}
"dbName" = {(Get-ChildItem -Path $global:TH_DBDir\RT5.7\).Name}
"patchSubDir" ={(Get-ChildItem -Path $global:TH_BinDir\Patches\).Name}
"hmiSubDir" = {(Get-ChildItem -Path $global:TH_HMIDir).Name}
"moduleScript" = {(Get-ChildItem -Path $global:TH_ModPaths).Name}
"items" = {"bins", "databases", "modules"}
}
两种解决方案都通过扩展单个 属性 name
.
的字符串来工作
我在 PowerShell 3 中使用 TabExpansion2,当我用 Tab 键完成一个参数时,它会显示我想要但包含在我不想要的语法中的字符串。
例如,当我在 -binName
之后点击制表符时:
Use-Bin -binName @{Name=5.0}
我需要的是:
Use-Bin -binName 5.0
我正在使用这个脚本:https://www.powershellgallery.com/packages/PowerShellCookbook/1.3.6/Content/TabExpansion.ps1
使用这些调整后的选项:
$options["CustomArgumentCompleters"] = @{
"binName" = {Get-ChildItem -Path $global:TH_BinDir | Select-Object Name}
"dbName" = {Get-ChildItem -Path $global:TH_DBDir\RT5.7\ | Select-Object Name}
"patchSubDir" ={Get-ChildItem -Path $global:TH_BinDir\Patches\ | Select-Object Name}
"hmiSubDir" = {Get-ChildItem -Path $global:TH_HMIDir | Select-Object Name}
"moduleScript" = {Get-ChildItem -Path $global:TH_ModPaths | Select-Object Name}
"items" = {"bins", "databases", "modules"}
}
谢谢!
我不熟悉 tabexpansion,但您的问题是您 returning 具有 name
属性的对象。您只想 return 字符串。
$options["CustomArgumentCompleters"] = @{
"binName" = {Get-ChildItem -Path $global:TH_BinDir | Select-Object -ExpandProperty Name}
"dbName" = {Get-ChildItem -Path $global:TH_DBDir\RT5.7\ | Select-Object -ExpandProperty Name}
"patchSubDir" ={Get-ChildItem -Path $global:TH_BinDir\Patches\ | Select-Object -ExpandProperty Name}
"hmiSubDir" = {Get-ChildItem -Path $global:TH_HMIDir | Select-Object -ExpandProperty Name}
"moduleScript" = {Get-ChildItem -Path $global:TH_ModPaths | Select-Object -ExpandProperty Name}
"items" = {"bins", "databases", "modules"}
}
由于您使用的是 3.0,这会更简洁并完成同样的事情。
$options["CustomArgumentCompleters"] = @{
"binName" = {(Get-ChildItem -Path $global:TH_BinDir).Name}
"dbName" = {(Get-ChildItem -Path $global:TH_DBDir\RT5.7\).Name}
"patchSubDir" ={(Get-ChildItem -Path $global:TH_BinDir\Patches\).Name}
"hmiSubDir" = {(Get-ChildItem -Path $global:TH_HMIDir).Name}
"moduleScript" = {(Get-ChildItem -Path $global:TH_ModPaths).Name}
"items" = {"bins", "databases", "modules"}
}
两种解决方案都通过扩展单个 属性 name
.