a very good cli file manager. need to use/research more http://www.youtube.com/watch?v=qooLR8NmYKs

1. help/resources

2. pending issue

  1. one slow tab slows all

    when using choose-file/dir, how to call ext-prog?

    A: use :shell command, @ as shortcut, plus "macro"(like %c), powerful!

  2. man page bash example doesn’t work?

    A: it actually works: need to then start ranger as "ranger-cd"

3. macros

%f   the highlighted file
%d   the path of the current directory
%s   the selected files in the current directory.
%t   all tagged files in the current directory
%c   the full paths of the currently copied/cut files

4. key-strokes

check .config/ranger/rc.config, everything is inside.

i :view the file W :see logs w :check Q list S :start a new shell f :real time search (:find) zf :only show some filtered files (:filter) / :search (not real time) v/<SPACE>/ :mark all, current file (:mark )

! :shell @ :shell %s ( is cursor position) # :shell -p ^

flags give you a way to modify the behavior of the spawned process.  They
are used in the commands ":open_with" (key "r") and ":shell" (key "!").
p   Redirect output to the (p)ager
s   (s)ilent mode.  Output will be discarded.
w   (w)ait for an Enter-press when the process is done
#w/p is useful to capture the output of a shell cmd
#start a shell, issue pwd, wait for a enter to go back ranger
:shell -w pwd
#another similar(some time better) way is:
:shell pwd;read

r :open-with m :mark things ' :refer things

gm :go media (go to /media)

#my customization

#ping, read pcap file when hitting "l" #ext pcap = tcpdump -SvvtttXXnr "$@" | vim - ext pcap = vim "$@"

#Pressing ",r" will first let you edit your rc.conf and then load it into #ranger with the :source command, so you don’t have to restart it. map ,r chain shell vim /.config/ranger/rc.conf; source /.config/ranger/rc.conf map ,a shell vim /.config/ranger/rifle.conf; source /.config/ranger/rc.conf map ,c shell vim /.config/ranger/commands.py; source /.config/ranger/rc.conf map ,s shell vim /.config/ranger/scope.sh; source /.config/ranger/rc.conf

key-binding (rc.config) examples:
#rc.config
# move to trash
map DD shell mv -t /home/myname/.config/ranger/Trash %s
bind app (rifle.conf) example:
~/.config/ranger/rifle.conf
#Since the beginning lines are executed first, you should put your
#modifications at the beginning of the file. For example, the following
#entry will open a tex file with kile.
ext tex = kile "$@"
Note tested, doesn’t work yet

5. help

? for man page 1? for a list of key bindings, 2? for a list of commands and 3? for a list of settings.

rc.conf

controls startup commands and key bindings .commands.py controls the commands which are launched with the ":" key .rifle.conf controls the applications used when a given type of file is launched.

6. command

:shell

only show any files containing PATTERN
:filter<CR>       reset the filter

:travel

7. commands (commands.py) examples::

Example 1. trash a file

#~/.config/ranger/commands.py class empty(Command): """:empty

Empties the trash directory ~/.Trash
"""
def execute(self):
    self.fm.run("rm -rf /home/myname/.Trash/{*,.[^.]*}")

#usage :empty<Enter>

Example 2. copy archive file and extract into current folder

#The following command implements archive extraction by copying (yy) one or more #archive files and then executing ":extracthere" on the desired directory.

import os from ranger.core.loader import CommandLoader

class extracthere(Command): def execute(self): """ Extract copied files to current directory """ copied_files = tuple(self.fm.env.copy)

if not copied_files:
    return
def refresh(_):
    cwd = self.fm.env.get_directory(original_path)
    cwd.load_content()
one_file = copied_files[0]
cwd = self.fm.env.cwd
original_path = cwd.path
au_flags = ['-X', cwd.path]
au_flags += self.line.split()[1:]
au_flags += ['-e']
self.fm.env.copy.clear()
self.fm.env.cut = False
if len(copied_files) == 1:
    descr = "extracting: " + os.path.basename(one_file.path)
else:
    descr = "extracting files from: " + os.path.basename(one_file.dirname)
obj = CommandLoader(args=['aunpack'] + au_flags \
        + [f.path for f in copied_files], descr=descr)
obj.signal_bind('after', refresh)
self.fm.loader.add(obj)

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.

Example 3. mark and compress

import os from ranger.core.loader import CommandLoader

class compress(Command): def execute(self): """ Compress marked files to current directory """ cwd = self.fm.env.cwd marked_files = cwd.get_selection()

if not marked_files:
    return
def refresh(_):
    cwd = self.fm.env.get_directory(original_path)
    cwd.load_content()
original_path = cwd.path
parts = self.line.split()
au_flags = parts[1:]
descr = "compressing files in: " + os.path.basename(parts[1])
obj = CommandLoader(args=['apack'] + au_flags + \
        [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr)
obj.signal_bind('after', refresh)
self.fm.loader.add(obj)
def tab(self):
    """ Complete with current folder name """
extension = ['.zip', '.tar.gz', '.rar', '.7z']
return ['compress ' + os.path.basename(self.fm.env.cwd.path) + ext for ext in extension]

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). Don’t 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.

Example 4. select and :mount

import os, time from ranger.core.loader import Loadable from ranger.ext.signals import SignalDispatcher from ranger.ext.shell_escape import *

class MountLoader(Loadable, SignalDispatcher): """ Wait until a directory is mounted """ def init(self, path): SignalDispatcher.init(self) descr = "Waiting for dir " + path + " to be mounted" Loadable.init(self, self.generate(), descr) self.path = path

def generate(self):
    available = False
    while not available:
        try:
            if os.path.ismount(self.path):
                available = True
        except:
            pass
        yield
        time.sleep(0.03)
    self.signal_emit('after')

class mount(Command): def execute(self): selected_files = self.fm.env.cwd.get_selection()

if not selected_files:
    return
space = ' '
self.fm.execute_command("cdemu -b system unload 0")
self.fm.execute_command("cdemu -b system load 0 " + \
        space.join([shell_escape(f.path) for f in selected_files]))
mountpath = "/media/virtualrom/"
def mount_finished(path):
    currenttab = self.fm.current_tab
    self.fm.tab_open(9, mountpath)
    self.fm.tab_open(currenttab)
obj = MountLoader(mountpath)
obj.signal_bind('after', mount_finished)
self.fm.loader.add(obj)

8. set options

:set show_hidden=True

9. email thread

On Sun, Feb 24, 2013 at 07:14:19PM -0500, ping wrote:
> a good tutorials to start with...
There are some tutorials out there for beginners if you google a
bit, for example [1], [2].  But I guess you're not a beginner
[1] https://wiki.archlinux.org/index.php/Ranger
[2] http://www.serverwatch.com/tutorials/article.php/3898746/Ranger-ConsoleBased-File-Management.htm
I assume that you know how to find the default configs and how to use
custom configs.  If not, check the "Customization" section of the
archlinux wiki page.
On Sun, Feb 24, 2013 at 07:14:19PM -0500, ping wrote:
> where can I get the how-tos or cheat-sheet kind of things?
> yes I know we have the man page, but I may not want to read through
> it for the commonly used commands.
if you search for COMMANDS in the man page, there is a brief listing of
all commands.  Often the names are self-explanatory.  Just skim through
it and look for things that sound useful to you.
The most commonly used commands are probably :delete, :shell (key
binding "!"), :search (key binding "/") and :filter (key binding "zf").
Useful commands for traveling fast are :travel and :find (key "f").
On Sun, Feb 24, 2013 at 07:14:19PM -0500, ping wrote:
> for example I know yy ,dd, pp can do copy/paste/cut quick, but they
> are my "guess" based on my knowledge of vim.
> but why dd won't delete the file? checking the manual I found
> :delete, or even :shell rm %f.
> so which is the best?
I recommend using :delete, because it will ask you for confirmation if
you try to delete more than 1 file or a non-empty directory.
You can also change the setting "confirm_on_delete" to make it
never/always ask you for confirmation.
Note that if you select multiple files with SPACE or "v" or ":mark" etc,
all of the selected files will be deleted.
Also, I can recommend you to skim through the key binding section of the
default rc.conf and look for things that you find useful.  Not all key
bindings are documented in the man page.  Useful key bindings are:
> map @  console -p6 shell  %%s
The @ key opens the console with "shell  %s" and puts the cursor at
position 6, between the two spaces, so you can enter commands quickly
that require the current selection as arguments.  E.g.: @mount<enter>
to mount the currently selected directory.
> map r  chain draw_possible_programs; console open_with
"r" displays a list of programs that are associated with this file type
and you can enter a number to select one and press enter, or type the
name of a completely different program.  You can also use flags here,
e.g.: rmplayer t<enter> opens the current file with mplayer, using the
flag "t" which makes mplayer open in a separate terminal.
check out the bindings starting with "g" for quick movement to important
directories.  you can of course add your own g-bindings by putting
something like this your custom ~/.config/ranger/rc.conf:
> map gX cd /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/plugin/include/ada/gcc-interface/secret_pron
To change permissions of files, you can use the key bindings starting
with - or +, for example "+ar" will execute "chmod a+r %s", "-ow" does
"chmod o-w %s" etc. I hope you see the pattern.
----------------------------------------
You can always make your own commands quickly by combining :alias,
:shell, :console and :chain.
> :alias <new command> <old command>
> :shell [-flags] <shell command>
> :console <line>
> :chain command1; command2; command3; ...
:alias will allow you to define new commands without editing any python code,
simply by combining existing commands.  :shell allows you to run any
:shell commands with certain flags, see FLAGS in the man page.  :console
will reopen the console with the given content, very useful for key
bindings like this:
> map F console shell -p find . | grep
And finally, chain lets you run multiple commands sequentially in a
single key binding or alias.
For example add this to your rc.conf:
> alias mount shell mount %f
Now go to a directory that is listed in fstab as mountable by users and
type :mount to mount it.
My favourite custom key bindings are probably these:
> map ,r chain shell vim ~/.config/ranger/rc.conf; source ~/.config/ranger/rc.conf
> map ,a shell vim ~/.config/ranger/rifle.conf
> map ,c shell vim ~/.config/ranger/commands.py
> map ,s shell vim ~/.config/ranger/scope.sh
Pressing ",r" will first let you edit your rc.conf and then load it into
ranger with the :source command, so you don't have to restart it.
The other ones only let you edit the configs, but you still have to
restart ranger.
On Sun, Feb 24, 2013 at 07:14:19PM -0500, ping wrote:
> also I want to make it display sth that does not come by default,
> like displaying a pcap file using tcpdump...
> how do I achieve that?
In the preview column?  Then what you're looking for is the
configuration file "scope.sh".  That's a shell script which tries to
print useful information about the given file, which is then fed into
the preview column of ranger.
Regards,
Roman