NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.38k stars 13.6k forks source link

ranger: Can't `. ranger` to keep current directory #265438

Open CyberShadow opened 10 months ago

CyberShadow commented 10 months ago

Describe the bug

In most distributions, one is able to e.g. alias r=". ranger" in their shell. Sourcing the ranger entry point script makes it preserve the current directory to the one that was being browsed in the file manager before quitting it.

However, this does not work in the nixpkgs version, because ranger is a nixpkgs-generated wrapper which uses exec, and thus cannot be sourced with the same effect.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Run . ranger
  2. Browse to a different directory
  3. Press q to quit Ranger

Expected behavior

The user should be returned to shell, in the directory browsed to in step 2.

Additional context

https://github.com/ranger/ranger/blob/136416c7e2ecc27315fe2354ecadfe09202df7dd/ranger.py#L6-L24

Notify maintainers

@toonn @magnetophon

Metadata

toonn commented 10 months ago

I think the easiest way forward here is probably to patch what the wrapper script would do directly into the ranger script.

duncanam commented 1 month ago

Hello, is there any more interest in adding this capability? I use this very frequently on non-nix machines.

CyberShadow commented 1 month ago

@IogaMaster Are you still working on this?

magnetophon commented 1 month ago

A possible workaround is to use yazi, which has a that functionality available as an alias as well: https://yazi-rs.github.io/docs/quick-start#shell-wrapper

Yazi is also a lot faster than ranger, and is regularly getting new releases.

EDIT: I feel a bit bad for saying this, right in front of one of the maintainers of ranger. Sorry @toonn, just know that imitation is the highest form of flattery, and ranger has spawned a whole slew of copycats!

CyberShadow commented 1 month ago

A possible workaround is to use yazi, which has a that functionality available as an alias as well:

Sorry, I don't understand. How does that help work around the problem here?

I tried nix-shell -p yazi and then both yazi and . yazi but neither allowed me to exit the file manager while preserving the current directory when returning to the shell.

magnetophon commented 1 month ago

There's a few lines of code in a couple shell languages here: https://yazi-rs.github.io/docs/quick-start#shell-wrapper Those will create a function that opens yazi (a ranger clone) and when you close yazi, you'll "be returned to shell, in the directory browsed to in step 2." (quote from the first comment in this issue)

IogaMaster commented 1 month ago

I completly forgot i added myself to this I will take a look this weekend

toonn commented 1 month ago

119052 actually tried implementing a solution to this years ago, maybe someone can pick that back up?