fnm icon indicating copy to clipboard operation
fnm copied to clipboard

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

Open netl0tuz opened this issue 1 year ago • 6 comments

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

netl0tuz avatar Jul 14 '23 14:07 netl0tuz

yes

chengkai2022 avatar Jul 18 '23 06:07 chengkai2022

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

Schniz avatar Jul 18 '23 07:07 Schniz

^ 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

Schniz avatar Jul 18 '23 07:07 Schniz

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 ?

netl0tuz avatar Jul 18 '23 08:07 netl0tuz

^ 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.

mataha avatar Jul 18 '23 23:07 mataha

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

Yakiyo avatar Aug 17 '23 15:08 Yakiyo