You are not logged in.

#1 2021-11-28 16:03:42

vEnhance
Member
Registered: 2021-11-28
Posts: 9
Website

Integrating fish with ranger?

Sorry if this the wrong forum / place or just a bad questions; feel free to move or dustbin mercilessly, so I know better next time.

I'm currently using Ranger and Fish daily. What I'm curious is whether there's a way to get these to work together better --- say, mostly having a ranger-based movement for cd's, and then executing shell commands once I'm in the right directory.

So far, the closest thing I can do is call the full shell from Ranger itself, but this clears all the ranger display data; or precede the command with '!', so I can only see the most recent command. What I'd really love is if I could view both command history and ranger listing at the same ime.

There might be really two separate questions here: is this possible already with built-in functions, and if not how might I write it myself?

Last edited by vEnhance (2021-11-28 19:21:30)


~ Evan Chen

Offline

#2 2021-11-29 01:35:22

lfitzgerald
Member
Registered: 2021-07-16
Posts: 175

Re: Integrating fish with ranger?

This is probably not a full solution, but ranger has a key mapping (several actually) to copy the current path. So what you could do is open ranger, navigate, copy path, quit and then paste it after cd. Or are you looking to automate it more?

Offline

#3 2021-12-01 00:15:06

vEnhance
Member
Registered: 2021-11-28
Posts: 9
Website

Re: Integrating fish with ranger?

Yeah I guess I was hoping to integrate it further. I'm imagining I have a split pane, where I enter terminal commands in one half while the contents of the current directory are listed in a second pane.

I'm gathering it might be easier for me to hack something together myself -- just thought to double check I wasn't missing anything obvious.


~ Evan Chen

Offline

#4 2021-12-01 04:43:02

lfitzgerald
Member
Registered: 2021-07-16
Posts: 175

Re: Integrating fish with ranger?

Well, don't be discouraged just me saying it, I only started using ranger recently. I'm a noob smile

I think I get the UX you're wanting. I'm also curious to see if anyone knows a way to do it, sounds pretty cool. However, in my setup I could pretty much do this already:

* Open ranger
* Open second terminal
* Tile it to the right (i3)
* Switch to ranger and navigate
* Press "copy line from terminal" key, it will highlight ranger's top bar with current wd, type the key combnation to copy it (kitty)
* Switch to the other one and paste it

I'm guessing you want them auto synchronized though, without pressing any more keys - that I'd also really like to know about! The only way I can think of is to not use ranger at all, but do some black magic in the shell prompt.

Offline

#5 2021-12-01 13:29:45

vEnhance
Member
Registered: 2021-11-28
Posts: 9
Website

Re: Integrating fish with ranger?

Sounds like we're on the same metaphorical page --- yeah, auto sync will be amazing.

Ranger is written in Python, it looks like, which conveniently is my native programming language. Maybe I'll try to make a fork with the deired effect, if it doesn't exist already?


~ Evan Chen

Offline

#6 2021-12-01 13:43:33

progandy
Member
Registered: 2012-05-17
Posts: 5,319

Re: Integrating fish with ranger?

You can use a ranger plugin and maybe a shell function (No idea if you can set fish to automatically refresh when a file is changed or so)

Here is something that logs the directories in ranger: https://github.com/ranger/ranger/wiki/I … grams#fasd

Last edited by progandy (2021-12-01 13:45:28)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |

Offline

#7 2021-12-01 14:36:36

vEnhance
Member
Registered: 2021-11-28
Posts: 9
Website

Re: Integrating fish with ranger?

I guess what I'm struggling with is that I can't (possibly due to my own ignorance) figure out how to get the shell to be inside a pane, so that the folder structure is still visible while I type commands. (I scrolled through https://github.com/ranger/ranger/tree/master/examples without too much success.)

Say, right now by default ranger has three panes. I'd like to replace the leftmost pane with a bona fide fish shell, while leaving the other two the same. And I'd like the cd of that leftmost shell to be the same as the directory of the center pane.


~ Evan Chen

Offline

#8 2021-12-01 16:22:05

progandy
Member
Registered: 2012-05-17
Posts: 5,319

Re: Integrating fish with ranger?

vEnhance wrote:

Say, right now by default ranger has three panes. I'd like to replace the leftmost pane with a bona fide fish shell, while leaving the other two the same. And I'd like the cd of that leftmost shell to be the same as the directory of the center pane.

Something like that is not possible without writing your own terminal emulator (or trying to embed one like pyte). It would be easier to just wrap ranger in tmux or use a tiling wm and open a separate terminal. (and have one command to auto-cd to the current ranger dir)

Edit: You could even control the tmux instance in a ranger plugin: https://github.com/tmux-python/libtmux
Edit: If you want to embed everything into ranger without tmux, maybe see if you can draw some ideas from e.g. https://github.com/prompt-toolkit/pymux
Edit: To sync fish to ranger, maybe start the second terminal from ranger, then in the started fish shell trap SIGUSR1 to read the new directory from a file and cd. the ranger plugin will write the current directory to that file and then send the signal.

Last edited by progandy (2021-12-01 17:12:56)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |

Offline

#9 2022-06-15 21:20:19

lfitzgerald
Member
Registered: 2021-07-16
Posts: 175

Re: Integrating fish with ranger?

Sorry for the necro, but this is probably a common question and I think I found the solution.

Ranger actually does support this in a couple ways. First, it prints cd commands on exit, so you just have to run "source ranger" (". ranger" also works) instead of "ranger" and when you quit, your shell will have cd'd to the directory ranger was in. The easy way of using this is to put "alias ranger='source ranger'". The source works for bash-style shells out of the box, but they have instructions for making it work on fish as well: https://github.com/ranger/ranger/wiki/I … irectories

Another one is ranger's "shift+s" key bind. This will open a new shell in ranger's dir. However you end up with 3 programs running (shell/ranger/shell) so usually this is not what you want. See alsohttps://unix.stackexchange.com/q/342064/520009

You could also try a similar utility lf (https://github.com/gokcehan/lf). This is more directly designed for your kind of usage, but I think it's less mature than ranger as a file manager.

Last edited by lfitzgerald (2022-06-15 21:21:24)

Offline

#10 2022-06-15 22:17:33

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,648

Re: Integrating fish with ranger?

Thanks for the contribution, but as you noted this thread is old and the OP has not been back for six months.

Closing.

Offline

Board footer

Powered by FluxBB