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

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

Open
CyberShadow opened this issue Nov 4, 2023 · 8 comments
Open

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

CyberShadow opened this issue Nov 4, 2023 · 8 comments

Comments

@CyberShadow
Copy link
Contributor

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

  • system: "x86_64-linux"
  • host os: Linux 6.5.4-arch2-1, Arch Linux, noversion, rolling
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.17.0
  • nixpkgs: /nix/store/l3bc30i71qshxa3mdj3dy8dj7zwqkh6s-source
@toonn
Copy link
Contributor

toonn commented Nov 4, 2023

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

@duncanam
Copy link

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

@CyberShadow
Copy link
Contributor Author

@IogaMaster Are you still working on this?

@magnetophon
Copy link
Member

magnetophon commented Jul 23, 2024

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
Copy link
Contributor Author

CyberShadow commented Jul 23, 2024

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
Copy link
Member

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
Copy link
Contributor

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

@toonn
Copy link
Contributor

toonn commented Jul 24, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants