From 887986ba794469fac718d542aa2479130cbbc9da Mon Sep 17 00:00:00 2001 From: Ravindu Liyanapathirana Date: Sat, 21 Mar 2026 22:42:59 +1100 Subject: [PATCH 1/3] Use existing `cd` command to `--use-on-cd` on PowerShell, instead of `Set-Location`. Fixes #1350 --- src/shell/powershell.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shell/powershell.rs b/src/shell/powershell.rs index 5468daa82..1c76dc74d 100644 --- a/src/shell/powershell.rs +++ b/src/shell/powershell.rs @@ -42,8 +42,10 @@ impl Shell for PowerShell { }; Ok(formatdoc!( r" + $global:cd_before_fnm = (Get-Command 'cd' -ErrorAction Ignore) + if (-not $global:cd_before_fnm) {{ $global:cd_before_fnm = 'Set-Location' }} function global:Set-FnmOnLoad {{ {autoload_hook} }} - function global:Set-LocationWithFnm {{ param($path); if ($path -eq $null) {{Set-Location}} else {{Set-Location $path}}; Set-FnmOnLoad }} + function global:Set-LocationWithFnm {{ param($path); if ($path -eq $null) {{ & $global:cd_before_fnm }} else {{ & $global:cd_before_fnm $path }}; Set-FnmOnLoad }} Set-Alias -Scope global cd_with_fnm Set-LocationWithFnm Set-Alias -Option AllScope -Scope global cd Set-LocationWithFnm ", From 9e3fd07950b0e36b88dc91bda4456775bda9f6ef Mon Sep 17 00:00:00 2001 From: Ravindu Liyanapathirana Date: Sat, 21 Mar 2026 23:04:48 +1100 Subject: [PATCH 2/3] Forward all args of `cd` function of `--use-on-cd` on PowerShell to underlying implementation --- src/shell/powershell.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shell/powershell.rs b/src/shell/powershell.rs index 1c76dc74d..5987c11e3 100644 --- a/src/shell/powershell.rs +++ b/src/shell/powershell.rs @@ -45,7 +45,7 @@ impl Shell for PowerShell { $global:cd_before_fnm = (Get-Command 'cd' -ErrorAction Ignore) if (-not $global:cd_before_fnm) {{ $global:cd_before_fnm = 'Set-Location' }} function global:Set-FnmOnLoad {{ {autoload_hook} }} - function global:Set-LocationWithFnm {{ param($path); if ($path -eq $null) {{ & $global:cd_before_fnm }} else {{ & $global:cd_before_fnm $path }}; Set-FnmOnLoad }} + function global:Set-LocationWithFnm {{ & $global:cd_before_fnm @args; Set-FnmOnLoad }} Set-Alias -Scope global cd_with_fnm Set-LocationWithFnm Set-Alias -Option AllScope -Scope global cd Set-LocationWithFnm ", From d8385d9938451d0301b47360e509b43d41de6ba0 Mon Sep 17 00:00:00 2001 From: Ravindu Liyanapathirana Date: Sat, 28 Mar 2026 10:24:40 +1100 Subject: [PATCH 3/3] Capture existing `cd` command in closure instead of global variable in PowerShell `--use-on-cd` script --- src/shell/powershell.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/shell/powershell.rs b/src/shell/powershell.rs index 5987c11e3..b3bc5f1b3 100644 --- a/src/shell/powershell.rs +++ b/src/shell/powershell.rs @@ -42,10 +42,12 @@ impl Shell for PowerShell { }; Ok(formatdoc!( r" - $global:cd_before_fnm = (Get-Command 'cd' -ErrorAction Ignore) - if (-not $global:cd_before_fnm) {{ $global:cd_before_fnm = 'Set-Location' }} function global:Set-FnmOnLoad {{ {autoload_hook} }} - function global:Set-LocationWithFnm {{ & $global:cd_before_fnm @args; 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 ",