Schniz / fnm

🚀 Fast and simple Node.js version manager, built in Rust
https://fnm.vercel.app
GNU General Public License v3.0
17.55k stars 445 forks source link

Documentation on "Shell Setup" is using wrong path for windows PowerShell profile #1009

Open netl0tuz opened 1 year ago

netl0tuz commented 1 year ago

Please consider changing Documentation of Shell Setup for windows, and use User Variable instead of ~ .

~\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

to 

 %userprofile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
chengkai2022 commented 1 year ago

yes

Schniz commented 1 year ago

Why? afaik in PowerShell ~ works. Moreover, env vars are referenced with $env:USERPROFILE and not %% like wincmd

Schniz commented 1 year ago

^ I’m on phone and it’s a textual form. This is a discussion. Please educate me, and assume every sentence ends with a question mark implicitly

netl0tuz commented 1 year ago

Please educate me, and assume every sentence ends with a question mark implicitly

sorry I'm not sure how to do that? I don't have much knowledge of PowerShell?

as for the reason i opened this discussion is because i want new (windows) users without knowledge of ~ meaning, be able to use fnm whiteout getting confused?

maybe this will solve posts like this issue too ?

Why? afaik in PowerShell ~ works. Moreover, env vars are referenced with $env:USERPROFILE and not %% like wincmd

Using code ~\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 , instead of creating profile file in desirable path , creates ~ folder ?

like this C:\Users\<username>\~\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 ?

somehow using command mkdir ~\Documents\WindowsPowerShell\ does create folder in right path ?

but again both vscode and notepad use C:\Users\<username>\~\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 instead ?

you are most likely using PowerShell on Mac or Linux , and that might be why ~ works correctly ?

mataha commented 1 year ago

^ I’m on phone and it’s a textual form. This is a discussion. Please educate me, and assume every sentence ends with a question mark implicitly

Depends what you're doing. For built-in commands PowerShell indeed expands ~ to the user's home directory if the parameter's type is a path (so Resolve-Path ~ will output what you would expect, while echo ~ will print a tilde as Write-Output takes a string instead of a path as its parameter). For native applications PowerShell 7.1.something provides an experimental feature that allows one to expand ~ wherever:

Enable-ExperimentalFeature PSNativePSPathResolution

After that code ~\(...)\Microsoft.PowerShell_profile.ps1 should work as expected.

But if you want to be 100% sure that you'll get the user's home directory, try:

${env:USERPROFILE}

Or even:

${env:HOMEDRIVE}${env:HOMEPATH}

As these work in every version of PowerShell, in every use-case.

Yakiyo commented 1 year ago

Isnt it enough to just use $profile to get the current active profile's pat? @tertek opened a new issue regarding that in #1027