Canop / broot

A new way to see and navigate directory trees : https://dystroy.org/broot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nushell: `cd` not working

Schweber opened this issue · comments

I am using broot 1.32.0 with nushell 0.89.0 and applied the argument expansion to the br shell function from #821

However, :open_leave doesn't work for me in nushell. I've set { key: "enter", execution: ":open_leave" } but if i press enter on a file/directory in broot, i'm back in the terminal without the folder having changed. Running pwd confirms this, so it's not a problem of the prompt not being updated.

Using { invocation: "cd", key: "enter", execution: "$SHELL", set_working_dir: true } "works" but this launches an additional instance of nu with the given folder so it's not a good workaround.

What could be the reason for this?

Just to be sure: you launch br, not broot ?

Yes, just double checked.

:open_leave isn't supposed (or able) to change the current directory of the opening shell.

Try with this:

{
    key: enter
    internal: open_leave
    apply_to: file
}
{
    key: enter
    external: "cd {directory}"
    from_shell: true
    apply_to: directory
}

Unfortunately, it's not working. I had { key: "enter", from_shell: true, execution: "cd {directory}", set_working_dir: true } for some time as a workaround for fish but in nu it's not working at all.

Is there a way to get a verbose output of broot to see why it fails? I found no such cli option...

Is there a way to get a verbose output of broot to see why it fails? I found no such cli option...

Yes, there's a log: https://dystroy.org/broot/community/#log

Thanks, it says this:

12:09:01.636 [DEBUG] broot::command::panel_input: verb for key: cd {directory}
12:09:01.636 [DEBUG] broot::app::app: command after add_event: VerbTrigger { verb_id: 13, input_invocation: None }
12:09:01.636 [DEBUG] broot::verb::execution_builder: repl name : "directory"
12:09:01.636 [INFO] broot::app::panel_state: get_status cc.cmd=VerbTrigger { verb_id: 13, input_invocation: None }
12:09:01.636 [DEBUG] broot::app::app: cmd_result: Quit
12:09:01.636 [DEBUG] broot::task_sync: dead dam
12:09:01.636 [INFO] cli_log::mem: Physical mem usage: current=12M, peak=154M
12:09:01.636 [INFO] broot: bye

broot.log

You don't have other verbs than the one I proposed mapped to the enter key ?

I'll have a deeper look and try on nushell but it won't be before a few days.

No, no further mappings to enter, just the ones you posted in this tread.

I just added this to be sure:

{
    key: Tab
    internal: open_leave
    apply_to: file
}
{
    key: Tab
    external: "cd {directory}"
    from_shell: true
    apply_to: directory
}

but it also is not working for me.

I updated to nushell 0.90.1 and broot 1.34.0 and reinstalled the br shell function but the problem is still there

I'm now on nushell 0.91. and broot 1.36.0 and the problem remains. These are the lines from the log where the cd is called and fails:

08:11:14.642 [INFO] broot::app::app: key combination: Enter
08:11:14.642 [DEBUG] broot::command::panel_input: verb for key: cd {directory}
08:11:14.642 [DEBUG] broot::app::app: command after add_event: VerbTrigger { verb_id: 13, input_invocation: None }
08:11:14.642 [DEBUG] broot::verb::execution_builder: repl name : "directory"
08:11:14.642 [DEBUG] broot::app::app: cmd_result: Quit
08:11:14.642 [DEBUG] broot::task_sync: dead dam
08:11:14.642 [INFO] cli_log::mem: Physical mem usage: current=13M, peak=154M
08:11:14.642 [INFO] broot: bye

broot.log

broot is not to blame, sorry. I had defined the alias in nushell config like this:

def a [] { br -gis }

This launched broot with the given flags but not the shell function somehow. If i do this instead:

alias a = br -gis 

everything works fine.

@FrancescElies @LudoPinelli @texastoland Is this behaviour to be expected from nushell or should it work in both instances?

@Schweber I think this is spected because of nushell scoping rules, the environment changes inside your def function stay there and do not have side effects outside the funciton, try with def --env a [] { br -gis }.

def --env is also what we used to define the br wrapper for nushell, see here

Try this two functions, cd-tmp will change directory of your current shell but cd-root won't.

def --env cd-tmp [] { cd /tmp; ls }
def cd-root [] { cd /; ls }

Does this help?

Yes, thank you for the explaination. I'll close this issue and make a PR to amend the documentation.