Ranger: improved config for 1.6.

master
Pierre Neidhardt 2013-02-23 18:49:44 +01:00
parent eb4b20cce6
commit 385e185a0d
5 changed files with 330 additions and 221 deletions

View File

@ -1,147 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2009, 2010, 2011 Roman Zimbelmann <romanz@lavabit.com>
# This configuration file is licensed under the same terms as ranger.
# ===================================================================
# In order to add application definitions "on top of" the default ones
# in your ~/.config/ranger/apps.py, you should subclass the class defined
# here like this:
import ranger
from ranger.api.apps import *
from ranger.ext.get_executables import get_executables
from ranger.defaults.apps import CustomApplications as DefaultApps
class CustomApplications(DefaultApps):
def app_default(self, c):
"""How to determine the default application?"""
f = c.file
if f.basename.lower() == 'makefile' and c.mode == 1:
made = self.either(c, 'make')
if made: return made
if f.extension is not None:
if f.extension in ('pdf', ):
c.flags += 'd'
return self.either(c, 'llpp', 'zathura', 'mupdf', 'apvlv',
'evince', 'okular', 'epdfview')
# CUSTOM
if f.extension == 'djvu':
c.flags += 'd'
return self.either(c, 'zathura', 'evince')
# CUSTOM
if f.extension == 'chm':
c.flags += 'd'
return self.either(c, 'xchm')
if f.extension == 'ps':
c.flags += 'd'
return self.either(c, 'zathura', 'evince')
# CUSTOM
if f.extension == 'svg':
c.flags += 'd'
return self.either(c, 'inkscape')
# CUSTOM
if f.extension == 'm2ts':
c.flags += 'd'
return self.either(c, 'mplayer2', 'mplayer', 'smplayer', 'vlc')
if f.extension in ('xml', 'csv'):
return self.either(c, 'editor')
if f.extension == 'mid':
return self.either(c, 'wildmidi')
if f.extension in ('html', 'htm', 'xhtml') or f.extension == 'swf':
c.flags += 'd'
handler = self.either(c,
'dwb', 'luakit', 'uzbl', 'vimprobable', 'vimprobable2', 'jumanji',
'firefox', 'seamonkey', 'iceweasel', 'opera',
'surf', 'midori', 'epiphany', 'konqueror')
# Only return if some program was found:
if handler:
return handler
if f.extension in ('html', 'htm', 'xhtml'):
# These browsers can't handle flash, so they're not called above.
c.flags += 'D'
return self.either(c, 'elinks', 'links', 'links2', 'lynx', 'w3m')
if f.extension == 'nes':
return self.either(c, 'fceux')
if f.extension in ('swc', 'smc', 'sfc'):
return self.either(c, 'zsnes')
if f.extension == 'doc':
c.flags += 'd'
return self.either(c, 'abiword', 'libreoffice',
'soffice', 'ooffice')
if f.extension in ('odt', 'ods', 'odp', 'odf', 'odg', 'sxc',
'stc', 'xls', 'xlsx', 'xlt', 'xlw', 'gnm', 'gnumeric'):
c.flags += 'd'
return self.either(c, 'gnumeric', 'kspread',
'libreoffice', 'soffice', 'ooffice')
if f.mimetype is not None:
if INTERPRETED_LANGUAGES.match(f.mimetype):
return self.either(c, 'edit_or_run')
if f.container:
return self.either(c, 'aunpack', 'file_roller')
# CUSTOM
if f.video or f.audio:
if f.video:
c.flags += 'd'
return self.either(c, 'mplayer2', 'mplayer', 'smplayer', 'vlc',
'totem')
# CUSTOM
if f.image:
if c.mode in (11, 12, 13, 14):
return self.either(c, 'set_bg_with_feh')
else:
return self.either(c, 'sxiv', 'feh', 'gpicview' , 'eog', 'mirage')
if f.document or f.filetype.startswith('text') or f.size == 0:
return self.either(c, 'editor')
# You can put this at the top of the function and mimeopen will
# always be used for every file.
return self.either(c, 'mimeopen')
# ----------------------------------------- application definitions
# Note: Trivial application definitions are at the bottom
# CUSTOM
@depends_on('feh', 'X')
def app_feh(self, c):
c.flags += 'd'
if c.mode is 0 and len(c.files) is 1 and self.fm.env.cwd:
# view all files in the cwd
images = [f.basename for f in self.fm.env.cwd.files if f.image]
return 'feh', '-Z', '-.', '--start-at', c.file.basename, images
return 'feh', '-Z', '-.', c
# Forked applications
CustomApplications.generic(
'dwb', 'luakit', 'uzbl', 'vimprobable', 'vimprobable2', 'jumanji',
'firefox', 'seamonkey', 'iceweasel', 'opera',
'surf', 'midori', 'epiphany', 'konqueror',
'evince', 'zathura', 'apvlv', 'okular', 'epdfview', 'mupdf', 'llpp',
'eog', 'mirage', 'gimp',
'libreoffice', 'soffice', 'ooffice', 'gnumeric', 'kspread', 'abiword',
'gmplayer', 'smplayer', 'vlc',
flags='d', deps=['X'])
INTERPRETED_LANGUAGES = re.compile(r'''
^(text|application)/x-(
haskell|perl|python|ruby|sh
)$''', re.VERBOSE)

View File

@ -3,20 +3,86 @@
# To change them, it is recommended to create the file
# ~/.config/ranger/rc.conf and add your custom commands there.
#
# If you copy this whole file there, add this line to your options.py
# so it is not loaded twice:
# If you copy this whole file there, you may want to set the environment
# variable RANGER_LOAD_DEFAULT_RC to FALSE to avoid loading it twice.
#
# load_default_rc = False
#
# The purpose of this file is mainly to define keybindings. For
# changing settings or running more complex python code, use the
# configuation file "options.py" or define commands in "commands.py".
# The purpose of this file is mainly to define keybindings and settings.
# For running more complex python code, please create a plugin in "plugins/" or
# a command in "commands.py".
#
# Each line is a command that will be run before the user interface
# is initialized. As a result, you can not use commands which rely
# on the UI such as :delete or :mark.
# ===================================================================
# ===================================================================
# == Options
# ===================================================================
# Which files should be hidden? (regular expression)
set hidden_filter ^\.
# Preview images in full color with the external command "w3mimgpreview"?
# This requires the console web browser "w3m" and a supported terminal.
# It has been successfully tested with "xterm" and "urxvt" without tmux.
set preview_images true
# Display the directory name in tabs?
set dirname_in_tabs true
# Enable the mouse support?
set mouse_enabled false
# How many directory-changes or console-commands should be kept in history?
set max_history_size 20
set max_console_history_size 50
# Try to keep so much space between the top/bottom border when scrolling:
set scroll_offset 8
# Flush the input after each key hit? (Noticable when ranger lags)
set flushinput true
# Padding on the right when there's no preview?
# This allows you to click into the space to run the file.
set padding_right true
# Save bookmarks (used with mX and `X) instantly?
# This helps to synchronize bookmarks between multiple ranger
# instances but leads to *slight* performance loss.
# When false, bookmarks are saved when ranger is exited.
set autosave_bookmarks false
# One of: size, basename, mtime, type
set sort natural
# Additional sorting options
set sort_reverse false
set sort_case_insensitive true
set sort_directories_first true
# Enable this if key combinations with the Alt Key don't work for you.
# (Especially on xterm)
set xterm_alt_key false
# ===================================================================
# == Local Options
# ===================================================================
# You can set local options that only affect a single directory.
# Examples:
# setlocal path=~/downloads sort mtime
# ===================================================================
# == Command Aliases in the Console
# ===================================================================
alias e edit
alias q quit
alias q! quitall
alias qall quitall
alias setl setlocal
# ===================================================================
# == Define keys for the browser
# ===================================================================
@ -28,15 +94,6 @@ map ! console shell -w
map <F4> bulkrename
map <F5> console shell -w file "%f"
map <F6> console touch
map <F7> console mkdir
map <F8> console delete seriously?
map <F10> exit
# ===================================================================
# == Personal options
# ===================================================================
set dirname_in_tabs true
# ===================================================================
# == Personal shorcuts
@ -48,8 +105,7 @@ set dirname_in_tabs true
## Move to trash (with Trash-CLI)
map DD shell trash-put -- %s
## Extraction. Ranger uses '1l', but does not work when extension is not
## right. Using atools instead.
## Extraction using atools.
map ex shell aunpack -e %s
map eeg shell aunpack -e %s -X "$HOME/games/"
@ -69,12 +125,10 @@ map es shell -w submarine %f
## Audio
map ea shell cmus-remote -P %s
## Mount iSO
## Mount ISO
map em shell fuseiso -p %f ~/iso
map eu shell fusermount -qu ~/iso
# Quick moves
map K move up=5
map J move down=5
#map <C-h> tab_move 1
#map <C-l> tab_move -1

195
.config/ranger/rifle.conf Normal file
View File

@ -0,0 +1,195 @@
# vim: ft=cfg
#
# This is the configuration file of "rifle", ranger's file executor/opener.
# Each line consists of conditions and a command. For each line the conditions
# are checked and if they are met, the respective command is run.
#
# Syntax:
# <condition1> , <condition2> , ... = command
#
# The command can contain these environment variables:
# $1-$9 | The n-th selected file
# $@ | All selected files
#
# If you use the special command "ask", rifle will ask you what program to run.
#
# Prefixing a condition with "!" will negate its result.
# These conditions are currently supported:
# match <regexp> | The regexp matches $1
# ext <regexp> | The regexp matches the extension of $1
# mime <regexp> | The regexp matches the mime type of $1
# name <regexp> | The regexp matches the basename of $1
# path <regexp> | The regexp matches the absolute path of $1
# has <program> | The program is installed (i.e. located in $PATH)
# file | $1 is a file
# directory | $1 is a directory
# number <n> | change the number of this command to n
# terminal | stdin, stderr and stdout are connected to a terminal
# X | $DISPLAY is not empty (i.e. Xorg runs)
#
# There are also pseudo-conditions which have a "side effect":
# flag <flags> | Change how the program is run. See below.
# label <label> | Assign a label or name to the command so it can
# | be started with :open_with <label> in ranger
# | or `rifle -p <label>` in the standalone executable.
# else | Always true.
#
# Flags are single characters which slightly transform the command:
# f | Fork the program, make it run in the background.
# | New command = setsid $command >& /dev/null &
# r | Execute the command with root permissions
# | New command = sudo $command
# t | Run the program in a new terminal. If $TERMCMD is not defined,
# | rifle will attempt to extract it from $TERM.
# | New command = $TERMCMD -e $command
# Note: The "New command" serves only as an illustration, the exact
# implementation may differ.
# Note: When using rifle in ranger, there is an additional flag "c" for
# only running the current file even if you have marked multiple files.
#-------------------------------------------
# Websites
#-------------------------------------------
# Rarely installed browsers get higher priority; It is assumed that if you
# install a rare browser, you probably use it. Firefox/konqueror/w3m on the
# other hand are often only installed as fallback browsers.
ext x?html?, has surf, X, flag f = surf -- file://"$1"
ext x?html?, has dwb, X, flag f = dwb -- "$@"
ext x?html?, has vimprobable, X, flag f = vimprobable -- "$@"
ext x?html?, has vimprobable2, X, flag f = vimprobable2 -- "$@"
ext x?html?, has jumanji, X, flag f = jumanji -- "$@"
ext x?html?, has luakit, X, flag f = luakit -- "$@"
ext x?html?, has uzbl, X, flag f = uzbl -- "$@"
ext x?html?, has uzbl-browser, X, flag f = uzbl-browser -- "$@"
ext x?html?, has uzbl-core, X, flag f = uzbl-core -- "$@"
ext x?html?, has midori, X, flag f = midori -- "$@"
ext x?html?, has chromium, X, flag f = chromium -- "$@"
ext x?html?, has opera, X, flag f = opera -- "$@"
ext x?html?, has firefox, X, flag f = firefox -- "$@"
ext x?html?, has seamonkey, X, flag f = seamonkey -- "$@"
ext x?html?, has iceweasel, X, flag f = iceweasel -- "$@"
ext x?html?, has epiphany, X, flag f = epiphany -- "$@"
ext x?html?, has konqueror, X, flag f = konqueror -- "$@"
ext x?html?, has elinks, terminal = elinks "$@"
ext x?html?, has links2, terminal = links2 "$@"
ext x?html?, has links, terminal = links "$@"
ext x?html?, has lynx, terminal = lynx -- "$@"
ext x?html?, has w3m, terminal = w3m "$@"
#-------------------------------------------
# Misc
#-------------------------------------------
# Define the "editor" for text files as first action
mime ^text, label editor = "$EDITOR" -- "$@"
mime ^text, label pager = "$PAGER" -- "$@"
!mime ^text, label editor, ext xml|csv|tex|py|pl|rb|sh|php = "$EDITOR" -- "$@"
!mime ^text, label editor, ext xml|csv|tex|py|pl|rb|sh|php = "$PAGER" -- "$@"
ext 1 = man "$1"
ext s[wmf]c, has zsnes, X = zsnes "$1"
ext nes, has fceux, X = fceux "$1"
ext exe = wine "$1"
name ^[mM]akefile$ = make
#--------------------------------------------
# Code
#-------------------------------------------
ext py = python -- "$1"
ext pl = perl -- "$1"
ext rb = ruby -- "$1"
ext sh = sh -- "$1"
ext php = php -- "$1"
#--------------------------------------------
# Audio without X
#-------------------------------------------
mime ^audio|ogg$, terminal, has mplayer = mplayer -- "$@"
mime ^audio|ogg$, terminal, has mplayer2 = mplayer2 -- "$@"
ext midi?, terminal, has wildmidi = wildmidi -- "$@"
#--------------------------------------------
# Video/Audio with a GUI
#-------------------------------------------
mime ^video|audio, has gmplayer, X, flag f = gmplayer -- "$@"
mime ^video|audio, has smplayer, X, flag f = smplayer "$@"
mime ^video, has mplayer2, X, flag f = mplayer2 -- "$@"
mime ^video, has mplayer2, X, flag f = mplayer2 -fs -- "$@"
mime ^video, has mplayer, X, flag f = mplayer -- "$@"
mime ^video, has mplayer, X, flag f = mplayer -fs -- "$@"
mime ^video|audio, has vlc, X, flag f = vlc -- "$@"
mime ^video|audio, has totem, X, flag f = totem -- "$@"
mime ^video|audio, has totem, X, flag f = totem --fullscreen -- "$@"
ext m2?ts, has mplayer2, X, flag f = mplayer2 -- "$@"
ext m2?ts, has mplayer, X, flag f = mplayer -- "$@"
#--------------------------------------------
# Video without X:
#-------------------------------------------
mime ^video, terminal, !X, has mplayer2 = mplayer2 -- "$@"
mime ^video, terminal, !X, has mplayer = mplayer -- "$@"
#-------------------------------------------
# Image Viewing:
#-------------------------------------------
mime ^image, has eog, X, flag f = eog -- "$@"
mime ^image, has sxiv, X, flag f = sxiv -- "$@"
mime ^image, has feh, X, flag f = feh -- "$@"
mime ^image, has mirage, X, flag f = mirage -- "$@"
mime ^image, has gimp, X, flag f = gimp -- "$@"
ext xcf, X, flag f = gimp -- "$@"
ext svg, has dwb, X, flag f = dwb -- "$@"
ext svg, has inkscape X, flag f = inkscape -- "$@"
#-------------------------------------------
# Documents
#-------------------------------------------
ext pdf, has llpp, X, flag f = llpp "$@"
ext pdf, has zathura, X, flag f = zathura -- "$@"
ext pdf, has mupdf, X, flag f = mupdf -- "$@"
ext pdf, has apvlv, X, flag f = apvlv -- "$@"
ext pdf, has xpdf, X, flag f = xpdf -- "$@"
ext pdf, has evince, X, flag f = evince -- "$@"
ext pdf, has okular, X, flag f = okular -- "$@"
ext pdf, has epdfview, X, flag f = epdfview -- "$@"
ext docx?, has catdoc, terminal = catdoc -- "$@" | "$PAGER"
ext sxc|xlsx?|xlt|xlw|gnm|gnumeric, has gnumeric, X, flag f = gnumeric -- "$@"
ext sxc|xlsx?|xlt|xlw|gnm|gnumeric, has kspread, X, flag f = kspread -- "$@"
ext od[dfgpst]|docx?|sxc|xlsx?|xlt|xlw|gnm|gnumeric, has libreoffice, X, flag f = libreoffice "$@"
ext od[dfgpst]|docx?|sxc|xlsx?|xlt|xlw|gnm|gnumeric, has soffice, X, flag f = soffice "$@"
ext od[dfgpst]|docx?|sxc|xlsx?|xlt|xlw|gnm|gnumeric, has ooffice, X, flag f = ooffice "$@"
ext djvu, has zathura, X, flag f = zathura -- "$@"
ext djvu, has evince, X, flag f = evince -- "$@"
ext chm, has xchm, X, flag f = xchm -- "$@"
ext ps, has zathura, X, flag f = zathura -- "$@"
#-------------------------------------------
# Archives
#-------------------------------------------
# This requires atool
ext 7z|ace|ar|arc|bz2?|cab|cpio|cpt|deb|dgc|dmg|gz, has als = als -- "$@" | "$PAGER"
ext iso|jar|msi|pkg|rar|shar|tar|tgz|xar|xpi|xz|zip, has als = als -- "$@" | "$PAGER"
ext 7z|ace|ar|arc|bz2?|cab|cpio|cpt|deb|dgc|dmg|gz, has aunpack = aunpack -- "$@"
ext iso|jar|msi|pkg|rar|shar|tar|tgz|xar|xpi|xz|zip, has aunpack = aunpack -- "$@"
# Fallback:
ext tar|gz, has tar = tar vvtf "$@" | "$PAGER"
ext tar|gz, has tar = tar vvxf "$@"
#-------------------------------------------
# Misc
#-------------------------------------------
label wallpaper, number 11, mime ^image, X = feh --bg-scale "$1"
label wallpaper, number 12, mime ^image, X = feh --bg-tile "$1"
label wallpaper, number 13, mime ^image, X = feh --bg-center "$1"
label wallpaper, number 14, mime ^image, X = feh --bg-fill "$1"
# Define the editor for non-text files + pager as last action
!mime ^text, !ext xml|csv|tex|py|pl|rb|sh|php = ask
label editor, !mime ^text, !ext xml|csv|tex|py|pl|rb|sh|php = "$EDITOR" -- "$@"
label pager, !mime ^text, !ext xml|csv|tex|py|pl|rb|sh|php = "$PAGER" -- "$@"

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env sh
# ranger supports enhanced previews. If the option "use_preview_script"
# is set to True and this file exists, this script will be called and its
# output is displayed in ranger. ANSI color codes are supported.
@ -29,32 +29,53 @@ mimetype=$(file --mime-type -Lb "$path")
extension=${path##*.}
# Functions:
# "have $1" succeeds if $1 is an existing command/installed program
function have { type -P "$1" > /dev/null; }
# "success" returns the exit code of the first program in the last pipe chain
function success { test ${PIPESTATUS[0]} = 0; }
# runs a command and saves its output into $output. Useful if you need
# the return value AND want to use the output in a pipe
try() { output=$(eval '"$@"'); }
# writes the output of the previouosly used "try" command
dump() { echo "$output"; }
# a common post-processing function used after most commands
trim() { head -n "$maxln"; }
# wraps highlight to treat exit code 141 (killed by SIGPIPE) as success
highlight() { command highlight "$@"; test $? = 0 -o $? = 141; }
case "$extension" in
# Archive extensions:
7z|a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\
rar|rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
als "$path" | head -n $maxln
success && exit 0 || acat "$path" | head -n $maxln && exit 3
exit 1;;
# PDF documents:
pdf)
pdftotext -l 10 -nopgbrk -q "$path" - | head -n $maxln | fmt -s -w $width
success && exit 0 || exit 1;;
# Archive extensions:
7z|a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\
rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
try als "$path" && { dump | trim; exit 0; }
try acat "$path" && { dump | trim; exit 3; }
try bsdtar -lf "$path" && { dump | trim; exit 0; }
exit 1;;
rar)
try unrar -p- lt "$path" && { dump | trim; exit 0; } || exit 1;;
# CUSTOM
# PDF documents:
pdf)
try pdftotext -l 10 -nopgbrk -q "$path" - && \
{ dump | trim | fmt -s -w $width; exit 0; } || exit 1;;
# BitTorrent Files
torrent)
try transmission-show "$path" && { dump | trim; exit 5; } || exit 1;;
# HTML Pages:
htm|html|xhtml)
try w3m -dump "$path" && { dump | trim | fmt -s -w $width; exit 4; }
try lynx -dump "$path" && { dump | trim | fmt -s -w $width; exit 4; }
try elinks -dump "$path" && { dump | trim | fmt -s -w $width; exit 4; }
;; # fall back to highlight/cat if the text browsers fail
## CUSTOM SUPPORT
ogg)
mediainfo "$path" | sed 's/ \+:/: /;'
success && exit 5 || exit 1;;
# MKV videos:
mkv)
mediainfo "$path" | sed 's/ \+:/: /;'
success && exit 5 || exit 1;;
# doc files:
doc)
antiword "$path"
success && exit 5 || exit 1;;
@ -64,48 +85,30 @@ case "$extension" in
odt)
odt2txt "$path"
success && exit 5 || exit 1;;
# BitTorrent Files
torrent)
transmission-show "$path" | head -n $maxln && exit 3
success && exit 5 || exit 1;;
# HTML Pages:
htm|html|xhtml)
have w3m && w3m -dump "$path" | head -n $maxln | fmt -s -w $width && exit 4
have lynx && lynx -dump "$path" | head -n $maxln | fmt -s -w $width && exit 4
have elinks && elinks -dump "$path" | head -n $maxln | fmt -s -w $width && exit 4
;; # fall back to highlight/cat if theres no lynx/elinks
esac
case "$mimetype" in
# Syntax highlight for text files:
text/* | */xml)
highlight --out-format=ansi "$path" | head -n $maxln
# Syntax highlight for text files:
text/* | */xml)
try highlight --out-format=ansi "$path" && { dump | trim; exit 5; } || exit 2;;
# FIXME: does not work!
# highlight --out-format=xterm256 -s zmrok "$path" | head -n $maxln
success && exit 5 || exit 2;;
# CUSTOM
image/*)
## Ascii-previews of images:
# img2txt --gamma=0.6 --width="$width" "$path" && exit 4 || exit 1;;
## Use sed to remove spaces so the output fits into the narrow window
if have mediainfo; then
mediainfo "$path" | sed 's/ \+:/: /;'
success && exit 5
fi
exit 1;;
# Ascii-previews of images:
image/*)
img2txt --gamma=0.6 --width="$width" "$path" && exit 4 || exit 1;;
## Alternative light preview.
# if have mediainfo; then
# mediainfo "$path" | sed 's/ \+:/: /;'
# success && exit 5
# fi
# exit 1;;
# Display information about media files:
video/* | audio/*)
have exiftool && exiftool "$path" && exit 5
# Use sed to remove spaces so the output fits into the narrow window
if have mediainfo; then
mediainfo "$path" | sed 's/ \+:/: /;'
success && exit 5
fi
exit 1;;
# Display information about media files:
video/* | audio/*)
exiftool "$path" && exit 5
# Use sed to remove spaces so the output fits into the narrow window
try mediainfo "$path" && { dump | trim | sed 's/ \+:/: /;'; exit 5; } || exit 1;;
esac
exit 1

View File

@ -44,6 +44,10 @@ elif [ "$TERM" != "dumb" ]; then
# export LSCOLORS="ExfxcxDxCxdxdxCxCxECEh"
fi
## This env variable is used by some programs (like ranger) to get terminal
## executable name.
export TERMCMD="urxvt"
## Terminal
## WARNING: this is always a bad idea!
## FreeBSD urxvt $TERM variable is not set properly for some reasons.