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

Add detection/launcher for Powershell #159

Open
stinos opened this issue Jan 14, 2020 · 9 comments
Open

Add detection/launcher for Powershell #159

stinos opened this issue Jan 14, 2020 · 9 comments
Labels
help wanted Extra attention is needed windows Windows specific problem

Comments

@stinos
Copy link

stinos commented Jan 14, 2020

In general it would be great if broot could detect which shell/environment it is running and install a suitable launcher; this issue in particular is for Powershell. Launchers have already been suggested in other issues, here's one take:

function br {
    $tempFile = New-TemporaryFile
    try {
        $broot = $env:BROOT
        if (-not $broot) {
             $broot = 'broot'
        }
        & $broot --outcmd $tempFile $args
        if ($LASTEXITCODE -ne 0) {
            Write-Error "$broot exited with code $LASTEXITCODE"
            return
        }
        $command = Get-Content $tempFile
        if ($command) {
            # broot returns extended-length paths but not all PowerShell/Windows
            # versions might handle this so strip the '\\?'
            Invoke-Expression $command.Replace("\\?\", "")
        }
    } finally {
        Remove-Item -force $tempFile
    }
}

$isDotSourced = $MyInvocation.InvocationName -eq '.' -or $MyInvocation.Line -eq ''
if (-not $isDotSourced) {
    br $args
}
  • works as a script so if this gets saved as br.ps1 somewhere, users can choose how they want to use it (dot-source it, or add path to file to the PATH or ...)
  • uses environment variable so users can set the path to the broot executable if broot isn't in the path for instance, or when developing and switching between versions etc. Defaults to broot instead of broot.exe so that it automatically works on pwsh on linux as well (tested on ubuntu 18.04)
@Canop
Copy link
Owner

Canop commented Jan 14, 2020

broot detects some shells, but not powershell, because I can't test that (I have no windows box).

I'd need some win10 rust developer to try adapt what is done for fish: https://github.com/Canop/broot/blob/master/src/shell_install/fish.rs#L94

@Canop Canop added the help wanted Extra attention is needed label Jan 15, 2020
@PDQDakota
Copy link

@Canop If it helps PowerShell is open source and cross platform. https://github.com/PowerShell/PowerShell#get-powershell

@Canop
Copy link
Owner

Canop commented Jan 15, 2020

@PDQDakota Thanks, I didn't knew. It seems it's not the same version which is released with Windows, if I correctly understand the readme. And installing this on linux would probably not lead to the typical installation I want to detect.
Moreover, I don't have the time to learn this shell, so I'd like a Rust Windows developer to look at this.

@Canop Canop pinned this issue Feb 4, 2020
@GrosSacASac
Copy link

Last time I tried, I compiled broot with the rust compiler then used the full path to the compiled broot inside powershell

@Canop Canop unpinned this issue Feb 16, 2020
@Canop Canop added the windows Windows specific problem label Jun 20, 2020
@pshirshov
Copy link

PowerShell Core works fine on MacOS and Linux. It would be really great if you add support for it.

@Canop
Copy link
Owner

Canop commented Sep 21, 2020

I lack time to study powershell at the moment, even on linux, so I'd need help for this.

@thisismygitrepo
Copy link

I can confirm the script works like a dream with latest version.

@adamency
Copy link

adamency commented Feb 1, 2023

Script works perfectly indeed. (Powershell 7.3.1 Win 10)

PS: I strongly suggest putting it in your $profile as is, instead of the clunky way it is done by broot which creates a file and needs to modify your path for such a small added feature.

@AeliusSaionji
Copy link

Looks like this one can be closed now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed windows Windows specific problem
8 participants