Ranger

From ArchWiki
Revision as of 18:22, 13 September 2010 by Julius2 (Talk | contribs)

Jump to: navigation, search

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:Ranger#)

Ranger is a text based file manager written in python with vi-style key bindings. It has an extensive feature set, and you can accomplish file management tasks with a few keystrokes with no need for the mouse.

Web Resources

Installation

Use the ranger-git PKGBUILD in AUR.

Comparison with other File Managers

Compared to graphical mouse-based file managers, Ranger is much more efficient, but still visually beautiful. Ranger has one pane with multiple columns for different directories in the path, and file previews on the right. Compared to double-pane file managers, Ranger shows more directory and file information. You can quickly move between directories using keystrokes, bookmarks or the command history. Previews of files and directory contents automatically show up for the current selection. Ranger's 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 has fewer features overall.

Documentation

Ranger has excellent built-in documentation. Just use these 4 keystrokes: "1?", "2?", "3?", or "4?".

Customization

After startup, Ranger creates a directory Template:Filename. You can copy any of the files from Template:Filename to Template:Filename and edit them as you like. Some basic knowledge of python is useful here. Template:Filename controls general options, Template:Filename controls key bindings, Template:Filename controls the commands which are launched with the ":" key, and Template:Filename controls the applications used when a given type of file is launched. You can launch files with "l" (ell) or "<Enter>". You need only include changes from the default files, but be sure to include any necessary headers. Also, if you change part of a function, be sure to include the whole thing, since you're redefining that function.

Binding keys

Use the file Template:Filename to modify key bindings.

There are different contexts for keybindings, including "browser", "console" and "pager". Before using map(), make sure to bind it to a context:

map = keymanager.get_context("browser")

A typical entry is:

map('gg', fm.move(to=0))

and you can change to a new key by replacing "gg".

The following example shows how to use "DD" to move selected files to a directory Template:Filename. Put this code in Template:Filename

# move to trash
@map('DD')
def movetotrash(arg):
   trash_dir = "/home/myname/.Trash"
   selection = arg.fm.env.get_selection()
   arg.fm.run(['mv', '-t', trash_dir] + [str(f) for f in selection])

By passing the arguments to run() as a list, you don't need to worry about escaping spaces or other special characters.


Defining commands

Continuing the above example, adding the following entry to Template:Filename would define a command to empty the trash directory Template:Filename.

class empty(Command):
 	def execute(self):
		self.fm.run("rm -rf /home/myname/.Trash/{*,.[^.]*}")

To use it, you would type ":empty<Enter>", using tab completion if desired.

Starting programs in the background

In many cases, launching a file will make Ranger unusable until the program you used to launch the file is closed. The following example shows how to change this for html files. In Template:Filename, change

if f.extension in ('html', 'htm', 'xhtml', 'swf'):
	return self.either(c, 'firefox', 'opera', 'elinks')

to

if f.extension in ('html', 'htm', 'xhtml', 'swf'):
	c.flags += 'd'
	return self.either(c, 'firefox', 'opera')

The option "d" stands for "detached". We removed "elinks" because it's a text-mode browser, and cannot be detached.