How to change directory in shell using Ranger

One of the uses of Ranger can be to conveniently change to a directory in the shell that launched Ranger. To do this, we use the --choosedir option of Ranger. Pass this the name of a file and when Ranger is closed it will write the directory it was in to that file. You can then read the contents of this file in your shell to change to that location.

For Bash, a function that can do this is provided in in the Ranger source code.

For Fish, I have written a similar function that you can add to your ~/.config/fish/

To use Ranger like this, invoke it at the shell as ranger-cd. When you quit Ranger, fish will change its current directory to that in Ranger.

Tried with: Ranger 1.6.1, Fish 2.0.0 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.