Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

broot --install on Windows PowerShell updates the wrong Profile.ps1 file #806

Open
alexxbb opened this issue Dec 4, 2023 · 7 comments
Open
Labels
bug Something isn't working windows Windows specific problem

Comments

@alexxbb
Copy link

alexxbb commented Dec 4, 2023

>> broot --version
>> broot 1.30.0

>> broot --install

Writing br shell function in C:\Users\arusev\AppData\Roaming\dystroy\broot\data\launcher\powershell\1.
Creating link from C:\Users\arusev\AppData\Roaming\dystroy\broot\config\launcher\powershell\br.ps1 to C:\Users\arusev\AppData\Roaming\dystroy\broot\data\launcher\powershell\1.
C:\Users\arusev\OneDrive - XXX\Documents\WindowsPowerShell\Profile.ps1 successfully patched.

However, my Profile file is different:
>> echo $PROFILE
>> C:\Users\arusev\OneDrive - XXX\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

@alexxbb alexxbb added the bug Something isn't working label Dec 4, 2023
@Canop
Copy link
Owner

Canop commented Dec 5, 2023

I'd like rusticians with knowledge of Windows to have a look there.

@Canop Canop added the windows Windows specific problem label Dec 5, 2023
@stinos
Copy link

stinos commented Dec 5, 2023

However, my Profile file is different:

But br still works, right?

See https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.3

So imo what broot does here is correct, and the best option as well.

@alexxbb
Copy link
Author

alexxbb commented Dec 5, 2023

But br still works, right?

Unfortunately no, I had to manually source the broot ps1 script in my $PROFILE, then br started working.

@stinos
Copy link

stinos commented Dec 6, 2023

Right, I missed that you're probably running PS Core, hence it looks in $HOME\Documents\PowerShell not $HOME\Documents\WindowsPowerShell (but note that PS will load both $HOME\Documents\PowerShell\Profile.ps1 and $HOME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1). I'm not sure if it's broot's job to fix this. Plus from a brief look over the code, it could be non-trivial to implement because the installation doesn't run in the shell but in Rust, and I'm not sure if that somehow has access to the shell which launched it somehow: ideally this should access $PSVersionTable or similar to check what it's being ran on.

Anyway, the typical fix for this PS/PS Core discrepancy is symlinking the WindowsPowershell to the Powershell directory or vice-versa.

@AeliusSaionji
Copy link

I think we should be revisiting this; the install script is currently in a broken state anyway* and we need to get eyes on it.

*: Last I checked, needs to be installed twice before br works, and then br will have you install it a third time 🤪

Note: PScore is typically referred to as pwsh, while the version currently bundled with Windows is referred to as WindowsPowerShell. This will be the familiar nomenclature to anyone who opted to install pwsh.

I propose the following change:

  1. Respect the $PROFILE env var. Do not just assume profile.ps1. It creates unnecessary clutter and confusion. If we're using Microsoft.PowerShell_profile.ps1 then that's what you should be patching. I'd also suggest that the above should be the preferred default instead of Profile.ps1, when creating the profile for the user.
  2. If the user has pwsh, patch pwsh and not WindowsPowerShell, unless maybe we're willing to add a y/n prompt, or implement more involved logic to detect if symlinks/sourcing are in play.

By the by,
Instead of symlinking, you may want to /source/ one profile from the other. Also, implement guard statements for things that are not supported in the older powershell 5.

If ((Get-Host).version.major -gt 5) {
  // this won't run in powershell 5
}

@Canop
Copy link
Owner

Canop commented Dec 27, 2023

A focused PR not touching other systems could be welcome here.

@k4lizen
Copy link

k4lizen commented Apr 23, 2024

Encountered exactly this issue today.
scoop install broot
broot --install
Still changes E:\Windows\Documents\WindowsPowerShell\Profile.ps1 and doesn't touch E:\Windows\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 so br doesn't work. Writing the patch to $profile seems quite reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working windows Windows specific problem
Projects
None yet
Development

No branches or pull requests

5 participants