You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On PowerShell, fnm env currently emits the following 👇, which alises cd to Set-LocationWithFnm:
# environment variables set with $env:... = ...functionglobal:Set-FnmOnLoad { fnm use --silent-if-unchanged }
functionglobal:Set-LocationWithFnm { param($path); if ($path-eq$null) {Set-Location} else {Set-Location$path}; Set-FnmOnLoad }
Set-Alias-Scope global cd_with_fnm Set-LocationWithFnmSet-Alias-Option AllScope -Scope global cd Set-LocationWithFnmSet-FnmOnLoad
Consequently, if cd is already aliased to a different command (e.g., as part of one's dotfiles, or a different command that similarly "patches" cd), fnm env | iex "drops" the current alias and resets it back to Set-Location.
For example,
cd is aliased to print out the path being navigated to, as a contrived example:
PS ~> cd Projects
customCd: Projects
PS ~/Projects>
FNM is loaded with fnm env --shell powershell --use-on-cd | Out-String | Invoke-Expression.
cd now prints:
PS ~> cd Projects/jsProject
Using Node v22.12.0
PS ~/Projects/jsProject>
...and global:customCd from step 1 is no longer invoked.
Proposed Solution
Thoughts on emitting a script like 👇? I've only included the cd-related bits; Set-FnmOnLoad and Set-LocationWithFnm are unchanged and omitted for brevity.
$global:cdBeforeFnm= (Get-Alias'cd'-Scope Global -ErrorAction Ignore).ReferencedCommand
if ($null-eq$global:cdBeforeFnm) { $global:cdBeforeFnm=Get-CommandSet-Location }
functionglobal:cdWithFnm {
param ($path)
if ($null-eq$path) { &$global:cdBeforeFnm } else { &$global:cdBeforeFnm$path }
global:Set-FnmOnLoad
}
Set-Alias'cd''global:cdWithFnm'-Option AllScope -Scope Global
...which uses the command that cd references at the time FNM is loaded, instead of always using Set-Location, thereby also invoking global:customCd:
PS ~> cd Projects/jsProject
customCd: Projects/jsProject
Using Node v22.12.0
PS ~/Projects/jsProject>
The text was updated successfully, but these errors were encountered:
Problem
On PowerShell,
fnm env
currently emits the following 👇, which alisescd
toSet-LocationWithFnm
:Consequently, if
cd
is already aliased to a different command (e.g., as part of one's dotfiles, or a different command that similarly "patches"cd
),fnm env | iex
"drops" the current alias and resets it back toSet-Location
.For example,
cd
is aliased to print out the path being navigated to, as a contrived example:...which has the following effect:
FNM is loaded with
fnm env --shell powershell --use-on-cd | Out-String | Invoke-Expression
.cd
now prints:...and
global:customCd
from step 1 is no longer invoked.Proposed Solution
Thoughts on emitting a script like 👇? I've only included the
cd
-related bits;Set-FnmOnLoad
andSet-LocationWithFnm
are unchanged and omitted for brevity....which uses the command that
cd
references at the time FNM is loaded, instead of always usingSet-Location
, thereby also invokingglobal:customCd
:The text was updated successfully, but these errors were encountered: