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

nushell: cd not working #827

Closed
Schweber opened this issue Jan 26, 2024 · 12 comments
Closed

nushell: cd not working #827

Schweber opened this issue Jan 26, 2024 · 12 comments
Labels
bug Something isn't working nushell

Comments

@Schweber
Copy link
Contributor

Schweber commented Jan 26, 2024

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?

@Schweber Schweber added the bug Something isn't working label Jan 26, 2024
@Schweber Schweber changed the title nushell: :open_leave not working nushell :open_leave not working Jan 26, 2024
@Schweber
Copy link
Contributor Author

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

Yes, just double checked.

@Canop
Copy link
Owner

Canop commented Jan 26, 2024

: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
}

@Schweber
Copy link
Contributor Author

Schweber commented Jan 26, 2024

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...

@Canop
Copy link
Owner

Canop commented Jan 26, 2024

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

@Schweber
Copy link
Contributor Author

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

@Canop
Copy link
Owner

Canop commented Jan 26, 2024

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.

@Schweber
Copy link
Contributor Author

Schweber commented Jan 26, 2024

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.

@Canop Canop added the nushell label Jan 29, 2024
@Schweber
Copy link
Contributor Author

Schweber commented Mar 4, 2024

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

@Schweber
Copy link
Contributor Author

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

@Schweber Schweber changed the title nushell :open_leave not working nushell: cd not working Mar 17, 2024
@Schweber
Copy link
Contributor Author

Schweber commented May 25, 2024

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?

@FrancescElies
Copy link
Contributor

FrancescElies commented May 25, 2024

@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?

@Schweber
Copy link
Contributor Author

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

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

No branches or pull requests

3 participants