PowerShell --use-on-cd enhancements#1535
Conversation
…`Set-Location`. Fixes Schniz#1350
…nderlying implementation
|
|
@ravindUwU is attempting to deploy a commit to the Gal Schlezinger's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
What's emitted now is 😄: function global: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-LocationWithFnmThe Re: |
…n PowerShell `--use-on-cd` script
ae3c405 to
d8385d9
Compare
|
Looks good to me. I agree that you could remove the alias. Realistically what I'm going to probably end up doing is figuring out what zoxide is doing and merging that and the Set-FnmOnLoad command into my custom one. |
|
Alternatively, I think function global:Set-FnmOnLoad { ... }
& {
$cd = (Get-Command 'cd' -ErrorAction Ignore)
if (-not $cd) { $cd = 'Set-Location' }
Set-Item Function:\global:cd_with_fnm { & $cd @args; Set-FnmOnLoad }.GetNewClosure()
}
Set-Alias -Option AllScope -Scope global cd cd_with_fnm...in fact I think I prefer this! The name A search for |
This PR includes the following changes for the
fnm env --use-on-cdscript emitted for PowerShell:cdcommand applicable when thefnm envscript is sourced is invoked by the emitted function, instead ofSet-Locationdirectly. Fixes Use existingcdalias in the script thatfnm env --shell powershell --use-on-cdemits #1350.cdfunction are forwarded to the underlyingcdfunction using splatting.Demo
With the following PowerShell profile,
Notice how, on PowerShell 5 & 7,
cd-ing uses FNM on cd, and delegates to thecustomCdfunction.cdfunction (in this case the-PassThruoption ofSet-Location) can be specified.