diff --git a/src/shell/powershell.rs b/src/shell/powershell.rs index 5468daa82..b3bc5f1b3 100644 --- a/src/shell/powershell.rs +++ b/src/shell/powershell.rs @@ -43,7 +43,11 @@ impl Shell for PowerShell { Ok(formatdoc!( r" function global:Set-FnmOnLoad {{ {autoload_hook} }} - function global:Set-LocationWithFnm {{ param($path); if ($path -eq $null) {{Set-Location}} else {{Set-Location $path}}; Set-FnmOnLoad }} + & {{ + $cd = (Get-Command 'cd' -ErrorAction Ignore) + if (-not $cd) {{ $cd = 'Set-Location' }} + Set-Item Function:\global:Set-LocationWithFnm {{ & $cd @args; Set-FnmOnLoad }}.GetNewClosure() + }} Set-Alias -Scope global cd_with_fnm Set-LocationWithFnm Set-Alias -Option AllScope -Scope global cd Set-LocationWithFnm ",