Revision as of 19:49, 7 April 2015

ranger is a text-based file manager written in Python. Directories are displayed in one pane with three columns. Moving between them is accomplished with keystrokes, bookmarks, the mouse or the command history. File previews and directory contents show automatically for the current selection.

Features include: vi-style key bindings, bookmarks, selections, tagging, tabs, command history, the ability to make symbolic links, several console modes, and a task view. ranger has customizable commands and key bindings, including bindings to external scripts. The closest competitor is Vifm, which has two panes and vi-style key bindings, but fewer features overall.

Compression

The following command allows the user to compress several files on the current directory by marking them and then calling :compress package name. It supports name suggestions by getting the basename of the current directory and appending several possibilities for the extension. You need to have atool installed. Otherwise you will see an error message when you create the archive.

External drives

External drives can be automatically mounted with udev or udisks. Drives mounted under /media can be easily accessed by pressing gm (go, media).

Image mounting

The following command assumes you are using cdemu as your image mounter and some kind of system like autofs which mounts the virtual drive to a specified location ('/media/virtualrom' in this case). Do not forget to change mountpath to reflect your system settings.

To mount an image (or images) to a cdemud virtual drive from ranger you select the image files and then type ':mount' on the console. The mounting may actually take some time depending on your setup (in mine it may take as long as one minute) so the command uses a custom loader that waits until the mount directory is mounted and then opens it on the background in tab 9.

New tab in current folder

You may have noticed there are two shortcuts for opening a new tab in home (gn and Ctrl+n). Let us rebind Ctrl+n:

rc.conf

map <c-n> eval fm.tab_new('%d')

Shell tips

Synchronize path

ranger provides a shell function/usr/share/doc/ranger/examples/bash_automatic_cd.sh. Running ranger-cd instead of ranger will automatically cd to the last browsed folder.

If you launch ranger from a graphical launcher (such as $TERMCMD -e ranger, where TERMCMD is an X terminal), you cannot use ranger-cd. Create an executable script:

ranger-launcher.sh

#!/bin/sh
export RANGERCD=true
$TERMCMD

and add at the very end of your shell configuration:

.shellrc

$RANGERCD && unset RANGERCD && ranger-cd

This will launch ranger-cd only if the RANGERCD variable is set. It is important to unset this variable again, otherwise launching a subshell from this terminal will automatically relaunch ranger.

Start a shell from ranger

With the previous method you can switch to a shell in last browsed path simply by leaving ranger. However you may not want to quit ranger for several reasons (numerous opened tabs, copy in progress, etc.).
You can start a shell from ranger (S by default) without losing your ranger session. Unfortunately, the shell will not switch to the current folder automatically. Again, this can be solved with an executable script:

shellcd

#!/bin/sh
export AUTOCD="$(realpath "$1")"
$SHELL

and - as before - add this to at the very end of your shell configuration:

shellrc

cd "$AUTOCD"

Now you can change your shell binding for ranger:

rc.conf

map S shell shellcd %d

Alternatively, you can make use of your shell history file if it has any. For instance, you could do this for zsh: