我正在使用一个函数,它可以执行一些更改目录功能,然后将/ re-alias 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这似乎是有道理的。
这是一个bug吗?或者,这是否与使用AllScope选项声明Set-Alias cd有关(我必须这样做,对于cd,如果没有它,Set-Alias将无法工作)
发布于 2020-03-21 00:51:40
您似乎遇到了错误,在PowerShell 7.0中仍然存在
大多数(Windows PowerShell) /少数(PowerShell核心6+)内置别名是使用AllScope选项定义的。
(您可以使用以下命令来发现它们
powershell -NoProfile { Get-Alias | ? options -like '*AllScope*' }
/
pwsh -NoProfile { Get-Alias | ? options -like '*AllScope*' })。
在调用方面,重新定义任何别名都可以正常工作。
然而,就 tab completed ,redefined tab ones malfunction而言,正如您所描述的:原始别名定义的参数仍在完成。
# Sample function
function foo { param($bar) "[$bar]" }
# Remove the built-in AllScope `cd` alias and redefine it to execute `foo`.
Remove-Item alias:cd; Set-Alias cd foo
# Make sure that the redefinition works:
cd -bar baz # OK: prints '[baz]'
# Try to tab-complete:
cd -b<tab> # NO COMPLETION instead of the expected '-bar'
# Try a parameter from `cd`'s *original* definition, `Set-Location`:
cd -li<tab> # UNEXPECTEDLY EXPANDS TO '-LiteralPath'已在this GitHub issue中报告了此问题行为。
https://stackoverflow.com/questions/60762540
复制相似问题