【发布时间】:2020-03-19 17:47:37
【问题描述】:
我正在使用一个可以执行一些更改目录功能的函数,然后将/重新别名 cd 重定向到该函数。
function go ($jumpto, [switch]$DisableAliasCD, [switch]$ResetGoHash, [switch]$ResetCDHistory) {
<stuff>
}
Set-Alias cc go
if (Test-Path Alias:cd) { Remove-Item -Path Alias:cd } # Remove the default: cd -> Set-Location
# Remove-Alias was not added until PS v6 so have to use Remove-Item with the Alias PSProvider
Set-Alias cd go -Option AllScope
检查每个go、cc、cd的语法
get-command go -syntax
go [[-jumpto] <Object>] [-DisableAliasCD] [-ResetGoHash] [-ResetCDHistory]
get-command cc -syntax
go
get-command cd -syntax
go
这似乎是有道理的。但是,我发现 IntelliSense 对于 cc 工作正常(即,如果我输入 cc - 然后 Tab 出现上述 4 个参数,但对于 cd 没有任何反应。
这是一个错误吗?或者这与使用AllScope 选项声明Set-Alias cd 有什么关系(我必须这样做,Set-Alias 没有它对于cd 不起作用)
【问题讨论】:
-
这次我已经在github.com/PowerShell/PowerShell/issues/12165 为您完成了,但我鼓励您下次尝试创建一个 - 我希望这个可以作为模型。
标签: powershell scope alias tab-completion