You are not logged in.

#1 2022-05-25 20:55:12

pradtf
Member
Registered: 2009-06-10
Posts: 134

SOLVED issue running broot's br from terminal

broot is an excellent and exception tui filemanager (imho):
https://dystroy.org/broot/

br is a function that calls broot and give provides some extra functionality.


this works from a terminal:
% alacritty -e broot

so does this:
% br

but this doesn't
% alacritty -e br
Error: Failed to spawn command 'br': No such file or directory (os error 2)

nor does this (but with a different error):
alacritty -e ~/.config/broot/launcher/bash/br
Error: Failed to spawn command '/home/pradmin/.config/broot/launcher/bash/br': Permission denied (os error 13)
os error 13: This error code indicates that the current user did not have permission to access an operating system file.

but i'm only writing to /tmp (afaik):

% alacritty -ve ~/.config/broot/launcher/bash/br
Created log file at "/tmp/Alacritty-80773.log"
[0.000000542s] [INFO ] [alacritty] Welcome to Alacritty
[0.000024354s] [INFO ] [alacritty] Version 0.10.1 (2844606d)
[0.000049120s] [INFO ] [alacritty] Running on X11
[0.000484108s] [INFO ] [alacritty] Configuration files loaded from:
                                     "/home/pradmin/.config/alacritty/alacritty.yml"
[0.047041092s] [INFO ] [alacritty] Device pixel ratio: 1
[0.048820741s] [INFO ] [alacritty] Initializing glyph cache...
[0.054239029s] [INFO ] [alacritty] ... finished initializing glyph cache in 0.005407297s
[0.054341626s] [INFO ] [alacritty] Cell size: 9 x 18
[0.054349156s] [INFO ] [alacritty] Padding: 0 x 0
[0.054352820s] [INFO ] [alacritty] Width: 800, Height: 600
[0.056101353s] [INFO ] [alacritty] PTY dimensions: 33 x 88
Deleted log file at "/tmp/Alacritty-80773.log"
Error: Failed to spawn command '/home/pradmin/.config/broot/launcher/bash/br': Permission denied (os error 13)

br is a function contained in ~/.local/share/boot/launcher/bash/1

# This script was automatically generated by the broot program
# More information can be found in https://github.com/Canop/broot
# This function starts broot and executes the command
# it produces, if any.
# It's needed because some shell commands, like `cd`,
# have no useful effect if executed in a subshell.
function br {
    local cmd cmd_file code
    cmd_file=$(mktemp)
    if broot --outcmd "$cmd_file" "$@"; then
        cmd=$(<"$cmd_file")
        rm -f "$cmd_file"
        eval "$cmd"
    else
        code=$?
        rm -f "$cmd_file"
        return "$code"
    fi
}

this file is symlinked with
.config/broot/launcher/bash/br -> /home/pradmin/.local/share/broot/launcher/bash/1
which is why i can run the function with br (i presume).

so i'm not sure why i'm getting this os error 13 when i try to run things by opening another terminal, but i'm fine if i just run br in a terminal.

what can be done to make it work?

Last edited by pradtf (2022-05-26 05:32:05)


in friendship,
prad

Offline

#2 2022-05-25 22:12:26

lmn
Member
Registered: 2021-05-09
Posts: 67

Re: SOLVED issue running broot's br from terminal

The br function is only available in bash, as it is probably sourced by any of bashs configuartion files. as it adds itself to ones shellrc of choice.
When you try to run this function (br) through alacritty it is not available as it is not a command found in $PATH. When you try to run the br file it fails as it is probably not executable. It would not matter though as executing it would do nothing (it is a valid shell script, but one that effectively is a noop ).

You could write a wrapper around that shell function and call that instead, something along the lines of

#!/bin/bash

source "~/.config/broot/launcher/bash/br"
br "$@"

Edit: stat ~/.config/broot/launcher/bash/br` would be useful in this situation

Last edited by lmn (2022-05-25 22:30:09)

Offline

#3 2022-05-26 03:36:54

pradtf
Member
Registered: 2009-06-10
Posts: 134

Re: SOLVED issue running broot's br from terminal

thx @imn.

your wrapper idea almost works. i've tried in the executable file
brit.sh

#!/bin/bash

source "/home/pradmin/.config/broot/launcher/bash/br"
br "$@" #as well as just br

and rewriting br as br1 (to keep it seperate from br)

function br1 {
    local cmd cmd_file code
    cmd_file=$(mktemp)
    if broot --outcmd "$cmd_file" "$@"; then
        cmd=$(<"$cmd_file")
        rm -f "$cmd_file"
        eval "$cmd"
    else
        code=$?
        rm -f "$cmd_file"
        return "$code"
    fi
}

br1 "$@" #and just br1

the file manager shows up nicely, but doesn't drop into the selected directory with Alt-enter - just keeps you in the same dir that the
alacritty -e brit.sh
was issued from.

this is different from
a) getting the error (with alacritty -e br)
b) alacritty -e broot (where the Alt-enter just doesn't work at all)

arguments seem to work fine
eg br1 -s (in the brit.sh file)
gives the sizes the way it should.

so it's a step closer!

br seems to call broot with some parameters:
if broot --outcmd "$cmd_file" "$@" ...
though i'm don't understand where it's getting the extra functionality.

i'm also trying to understand the bash.rs file.

Last edited by pradtf (2022-05-26 04:26:43)


in friendship,
prad

Offline

#4 2022-05-26 05:31:36

pradtf
Member
Registered: 2009-06-10
Posts: 134

Re: SOLVED issue running broot's br from terminal

however, this works!!!

alacritty -e sh -c "source /home/pradmin/.config/broot/launcher/bash/br;br;zsh"

and we don't need the brit.sh wrapper, though it works too if you stick a zsh|bash at the end:

#!/bin/zsh

source "/home/pradmin/.config/broot/launcher/bash/br"
br
zsh

exit

not quite sure what the ending zsh accomplished, but it seems to serve a similar purpose to --hold (which doesn't work at all, btw), in that it keeps things from reverting back to the initial directory.


in friendship,
prad

Offline

#5 2022-05-29 10:20:18

lmn
Member
Registered: 2021-05-09
Posts: 67

Re: SOLVED issue running broot's br from terminal

pradtf wrote:

not quite sure what the ending zsh accomplished

Just to elaborate on how this works:

alacritty is starts executing sh which sources the file containing the br function. It now proceeds to call the br function and changes into the selected directory. The br function has to use this workaround as the current working directory cannot be changed by a subprocess.
br solves this by using a temporary file which is read and executed in the parent process. After the broot process ends and the directory is changed zsh is started. The invocation of zsh (depending on the fact that the relevant shell configuration files don't mess with any of this) then starts an interactive shell in the (newly changed) current working directory.


As a note you are sourcing a bash script from inside a POSIX shell session. This is not recomended and can lead to unexpected behavior. On Arch this is somewhat mitigated by the fact that sh points to bash running in a POSIX compliant mode.

Edit: grammar

Last edited by lmn (2022-05-29 10:21:33)

Offline

#6 2022-05-29 17:14:26

pradtf
Member
Registered: 2009-06-10
Posts: 134

Re: SOLVED issue running broot's br from terminal

@imn thx for the explanations!!

lmn wrote:

After the broot process ends and the directory is changed zsh is started. The invocation of zsh (depending on the fact that the relevant shell configuration files don't mess with any of this) then starts an interactive shell in the (newly changed) current working directory.

ok! so without a zsh (sh or bash), there is no interactive shell and the thing just flashes and disappears!


lmn wrote:

As a note you are sourcing a bash script from inside a POSIX shell session. This is not recomended and can lead to unexpected behavior. On Arch this is somewhat mitigated by the fact that sh points to bash running in a POSIX compliant mode.

so, does this mean that it is better to source from inside a script by running the script - ie your wrapper idea?
the script has a shebang #!/bin/bash, but running it doesn't create a POSIX shell session then?

EDIT (22-05-30):
i just found out what you mean about unpredictable behavior, imn!
on one computer it was working fine, but not on the second. then it stopped working on the first after a reboot!
so i've gone to running from the script (brit.sh) and things are fine now.

Last edited by pradtf (2022-05-30 17:38:17)


in friendship,
prad

Offline

#7 2022-06-05 11:49:13

lmn
Member
Registered: 2021-05-09
Posts: 67

Re: SOLVED issue running broot's br from terminal

the script has a shebang #!/bin/bash, but running it doesn't create a POSIX shell session then?

It does not only create a POSIX shell session but a propper bash session. Which means you can use functionality that is not covered under POSIX such as `local` keyword for variables.

Your other question has been answered by time.

Offline

Board footer

Powered by FluxBB