Open Trid-collab opened 3 years ago
It's a incomplete question, what difficulty do you have ?
This is documentation available here
This is the message I am getting when I try to run "br" It works when I type broot
The br
is a shell function which needs installation. When you have a shell like bash or zsh installed, broot can install the br function. This should work on WSL but I have no competence on this OS.
Without such shell, I don't know how to define a br function. I think that some Windows users did make a br shell function but I can't help you here.
Windows users would be welcome to chime in.
my workflow on powershell is:
cargo install broot
broot
work perfectly.
On different note installing broot using cargo on my wsl2 setup +Ubunut 20.04 on win10 fails
@Trid-collab "fails" isn't really precise enough for me to try fix it. What happened ?
I'll install Ubuntu 20.04 on wsl2 and report back if I have any issues.
I just ran into this, too: when you run broot
for the first time, it will ask to install a shell wrapper to launch broot
as br
. broot
will install wrappers for bash
, zsh
, and fish
(which are completely useless on Windows) but will not install a wrapper for PowerShell or Cmd. Despite of that it will claim success.
The fix is obvious: don't try to install the br
wrappers on Windows (where they are useless) but notify the user that cd
support is not implemented on Windows yet.
Documenting the limited Windows support in the documentation would probably also lead to less frustration for Windows users.
br
is very close to working on windows in git bash. If you run br
and press alt+enter, broot writes this to the outcmd file:
cd C:\Users\John
The slashes are not quoted/escaped, so running that command results in this error:
sh: cd: C:UsersJohn: No error
If the path was escaped, it would work perfectly.
Here, I mocked this up. Windows users please test and let me know if there are issues.
Add it to your powershell profile (in powershell, echo $PROFILE
to see where the file should go if you don't have one yet, or notepad $PROFILE
to jump right into it).
Note: on Windows Alt-Enter is swallowed by the terminal, used to make it fullscreen. You can unbind Alt-Enter with the new Windows Terminal, but not the built in ones. For those, you'll have to just use broot's :cd
command directly.
Function br {
$args = $args -join ' '
$cmd_file = New-TemporaryFile
$process = Start-Process -FilePath 'broot.exe' `
-ArgumentList "--outcmd $($cmd_file.FullName) $args" `
-NoNewWindow -Wait -PassThru -WorkingDirectory $PWD
If ($process.ExitCode -eq 0) {
$cmd = Get-Content $cmd_file
Remove-Item $cmd_file
If ($cmd -ne $null) {
Invoke-Expression -Command $cmd
}
} Else {
Remove-Item $cmd_file
Write-Warning "broot exited with error code $process.ExitCode"
}
}
It occurs to me: I'm very new to broot and I don't know what commands other than cd
broot may try to invoke.
Is there a list somewhere?
edit: from the verbs doc page, seems like the only builtin external command is cd.
User custom made external commands will work if they are written in powershell.
@AeliusSaionji I gave it a try and it works well with just one issue: when I call :cd
it closes broot, then hangs the terminal for about 1-2 seconds before changing the directory.
Try this:
Function br {
$args = $args -join ' '
$cmd_file = New-TemporaryFile
$process = Start-Process -FilePath 'broot.exe' `
-ArgumentList "--outcmd $($cmd_file.FullName) $args" `
-NoNewWindow -PassThru -WorkingDirectory $PWD
Wait-Process -InputObject $process #Faster than Start-Process -Wait
If ($process.ExitCode -eq 0) {
$cmd = Get-Content $cmd_file
Remove-Item $cmd_file
If ($cmd -ne $null) { Invoke-Expression -Command $cmd }
} Else {
Remove-Item $cmd_file
Write-Host "`n" # Newline to tidy up broot unexpected termination
Write-Error "broot.exe exited with error code $($process.ExitCode)"
}
}
For completion's sake (:smirk:), here's how to set up tab completions, too.
In $PROFILE
,
# invoke broot as br
. path\to\br.ps1
# broot/br tab completions
. path\to\_br.ps1
. path\to\_broot.ps1
The br.ps1 is the code at the top of this post. The tab completion files are here: https://dystroy.org/broot/download/completion/_br.ps1 https://dystroy.org/broot/download/completion/_broot.ps1
ah, someone else shared a slightly different solution months ago.
Their's won't support custom user commands, but it does have broot make use of pushd/popd instead of cd.
Shall we document this solution somewhere or are there open questions?
@saona-raimundo As I don't know Powershell and have no Windows machine to test, I'd need several users to decide what's the best script. From there I could for example add it on the broot site.
@saona-raimundo As I don't know Powershell and have no Windows machine to test, I'd need several users to decide what's the best script. From there I could for example add it on the broot site.
The function from #588 sometimes throws an error:
$dir = $cd.substring(3)
| ~~~~~~~~~~~~~~~~~~~~~~~
| You cannot call a method on a null-valued expression.
So, it's better to use the function from @AeliusSaionji. And this definitely should be in the docs. And for the "alt-enter" it's better to change hotkey in verbs.hjson to ctrl-enter:
{
apply_to: directory
key: "ctrl-enter"
external: "cd {file}"
from_shell: true
}
I've been using br on windows without issue in nushell
.
Maybe is duplicate from: "https://github.com/Canop/broot/issues/788"
I solve my problem here: https://github.com/Canop/broot/issues/788#issuecomment-2094525162
Thanks.
How do I launch broot as br in Windows 10