Skip to content
Browse files

Update fsniper & ranger

  • Loading branch information...
1 parent 0c5244c commit 6b2b316f2d27ff8fc7bce76913f66684e2acc7d7 @JackH79 committed
Showing with 335 additions and 96 deletions.
  1. +31 −0 .config/fsniper/config
  2. +214 −0 .config/ranger/apps.py
  3. +2 −80 .config/ranger/commands.py
  4. +13 −16 .config/ranger/options.py
  5. +75 −0 .config/ranger/scope.sh
View
31 .config/fsniper/config
@@ -0,0 +1,31 @@
+watch {
+ # watch the ~/drop directory for new files
+ ~/Downloads {
+ # matches any mimetype beginning with image/
+ image/* {
+ # %% is replaced with the filename of the new file
+ handler = mv %% /home/jack/Downloads/pic/
+ }
+ audio/* {
+ handler = mv %% /home/jack/Downloads/audio/
+ }
+ video/* {
+ handler = mv %% /home/jack/Downloads/vid/
+ }
+ text/* {
+ handler = mv %% /home/jack/Downloads/doc/
+ }
+ application/msword {
+ handler = mv %% /home/jack/Downloads/doc/
+ }
+ application/vnd.* {
+ handler = mv %% /home/jack/Downloads/doc/
+ }
+ /\.(pdf|ps)$/ {
+ handler = mv %% /home/jack/Downloads/pdf/
+ }
+ /\.(gz|bz2|lz|xz|zip|rar)$/ {
+ handler = mv %% /home/jack/Downloads/tar/
+ }
+ }
+}
View
214 .config/ranger/apps.py
@@ -0,0 +1,214 @@
+import ranger
+from ranger.api.apps import *
+from ranger.ext.get_executables import get_executables
+
+class CustomApplications(Applications):
+ 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', ):
+ return self.either(c, 'zathura', 'okular', 'apvlv')
+ if f.extension == 'djvu':
+ return self.either(c, 'okular')
+ if f.extension == 'xml':
+ return self.either(c, 'editor')
+ if f.extension in ('html', 'htm', 'xhtml'):
+ return self.either(c, 'firefox', 'opera', 'jumanji', 'luakit', 'elinks', 'lynx')
+ if f.extension == 'mht':
+ return self.either(c, 'firefox')
+ if f.extension == 'swf':
+ return self.either(c, 'firefox', 'opera', 'jumanji', 'luakit')
+ if f.extension in ('epub', 'mobi'):
+ return self.either(c, 'ebook-viewer')
+ if f.extension == 'nes':
+ return self.either(c, 'fceux')
+ if f.extension in ('swc', 'smc', 'sfc'):
+ return self.either(c, 'zsnes')
+ if f.extension == 'vob':
+ return self.either(c, 'mplayer2')
+ if f.extension in ('odt', 'ods', 'odp', 'odf', 'odg',
+ 'rtf', 'doc', 'xls'):
+ return self.either(c, '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')
+
+ if f.video or f.audio:
+ if f.video:
+ c.flags += 'd'
+ return self.either(c, 'mplayer2', 'mplayer', 'smplayer', 'vlc',
+ 'totem')
+
+ 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', '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
+ def app_pager(self, c):
+ return 'less', '-R', c
+
+ def app_editor(self, c):
+ try:
+ default_editor = os.environ['EDITOR']
+ except KeyError:
+ pass
+ else:
+ parts = default_editor.split()
+ exe_name = os.path.basename(parts[0])
+ if exe_name in get_executables():
+ return tuple(parts) + tuple(c)
+
+ return self.either(c, 'vim', 'emacs', 'nano')
+
+ def app_edit_or_run(self, c):
+ if c.mode is 1:
+ return self.app_self(c)
+ return self.app_editor(c)
+
+ @depends_on('mplayer')
+ def app_mplayer(self, c):
+ if c.mode is 1:
+ return 'mplayer', '-fs', c
+
+ elif c.mode is 2:
+ args = "mplayer -fs -sid 0 -vfm ffmpeg -lavdopts " \
+ "lowres=1:fast:skiploopfilter=all:threads=8".split()
+ args.extend(c)
+ return args
+
+ elif c.mode is 3:
+ return 'mplayer', '-mixer', 'software', c
+
+ else:
+ return 'mplayer', c
+
+ @depends_on('mplayer2')
+ def app_mplayer2(self, c):
+ args = list(self.app_mplayer(c))
+ args[0] += '2'
+ return args
+
+ # A dependence on "X" means: this programs requires a running X server!
+ @depends_on('feh', 'X')
+ def app_set_bg_with_feh(self, c):
+ c.flags += 'd'
+ arg = {11: '--bg-scale', 12: '--bg-tile', 13: '--bg-center',
+ 14: '--bg-fill'}
+ if c.mode in arg:
+ return 'feh', arg[c.mode], c.file.path
+ return 'feh', arg[11], c.file.path
+
+ @depends_on('feh', 'X')
+ def app_feh(self, c):
+ c.flags += 'd'
+ if c.mode is 0 and len(c.files) is 1: # view all files in the cwd
+ images = [f.basename for f in self.fm.env.cwd.files if f.image]
+ return 'feh', '--start-at', c.file.basename, images
+ return 'feh', c
+
+ @depends_on('sxiv', 'X')
+ def app_sxiv(self, c):
+ c.flags = 'd' + c.flags
+ if len(c.files) is 1:
+ images = [f.basename for f in self.fm.env.cwd.files if f.image]
+ try:
+ position = images.index(c.file.basename) + 1
+ except:
+ return None
+ return 'sxiv', '-n', str(position), images
+ return 'sxiv', c
+
+ @depends_on('aunpack')
+ def app_aunpack(self, c):
+ if c.mode is 0:
+ c.flags += 'p'
+ return 'aunpack', '-l', c.file.path
+ return 'aunpack', c.file.path
+
+ @depends_on('file-roller', 'X')
+ def app_file_roller(self, c):
+ c.flags += 'd'
+ return 'file-roller', c.file.path
+
+ @depends_on('make')
+ def app_make(self, c):
+ if c.mode is 0:
+ return "make"
+ if c.mode is 1:
+ return "make", "install"
+ if c.mode is 2:
+ return "make", "clear"
+
+ @depends_on('java')
+ def app_java(self, c):
+ def strip_extensions(file):
+ if '.' in file.basename:
+ return file.path[:file.path.index('.')]
+ return file.path
+ files_without_extensions = map(strip_extensions, c.files)
+ return "java", files_without_extensions
+
+ @depends_on('totem', 'X')
+ def app_totem(self, c):
+ if c.mode is 0:
+ return "totem", c
+ if c.mode is 1:
+ return "totem", "--fullscreen", c
+
+ @depends_on('mimeopen')
+ def app_mimeopen(self, c):
+ if c.mode is 0:
+ return "mimeopen", c
+ if c.mode is 1:
+ # Will ask user to select program
+ # aka "Open with..."
+ return "mimeopen", "--ask", c
+
+
+# Often a programs invocation is trivial. For example:
+# vim test.py readme.txt [...]
+#
+# This could be implemented like:
+# @depends_on("vim")
+# def app_vim(self, context):
+# return "vim", context
+#
+# But this is redundant and ranger does this automatically. However, sometimes
+# you want to change some properties like flags or dependencies.
+# The method "generic" defines a generic method for the given programs which
+# looks like the one above, but you can add dependencies and flags here.
+# Add programs (that are not defined yet) here if they should only run in X:
+CustomApplications.generic('fceux', 'wine', 'zsnes', deps=['X'])
+
+# Add those which should only run in X AND should be detached/forked here:
+CustomApplications.generic('opera', 'firefox', 'okular', 'ebook-viewer', 'apvlv',
+ 'evince', 'zathura', 'gimp', 'mirage', 'eog', 'jumanji',
+ flags='d', deps=['X'])
+
+# What filetypes are recognized as scripts for interpreted languages?
+# This regular expression is used in app_default()
+INTERPRETED_LANGUAGES = re.compile(r'''
+ ^(text|application)/x-(
+ haskell|perl|python|ruby|sh
+ )$''', re.VERBOSE)
View
82 .config/ranger/commands.py
@@ -1,81 +1,3 @@
-# -*- coding: utf-8 -*-
-# Copyright (C) 2009, 2010, 2011 Roman Zimbelmann <romanz@lavabit.com>
-# This configuration file is licensed under the same terms as ranger.
-# ===================================================================
-# This file contains ranger's commands.
-# It's all in python; lines beginning with # are comments.
-#
-# Note that additional commands are automatically generated from the methods
-# of the class ranger.core.actions.Actions.
-#
-# You can customize commands in the file ~/.config/ranger/commands.py.
-# It has the same syntax as this file. In fact, you can just copy this
-# file there with `ranger --copy-config=commands' and make your modifications.
-# But make sure you update your configs when you update ranger.
-#
-# ===================================================================
-# Every class defined here which is a subclass of `Command' will be used as a
-# command in ranger. Several methods are defined to interface with ranger:
-# execute(): called when the command is executed.
-# cancel(): called when closing the console.
-# tab(): called when <TAB> is pressed.
-# quick(): called after each keypress.
-#
-# The return values for tab() can be either:
-# None: There is no tab completion
-# A string: Change the console to this string
-# A list/tuple/generator: cycle through every item in it
-#
-# The return value for quick() can be:
-# False: Nothing happens
-# True: Execute the command afterwards
-#
-# The return value for execute() and cancel() doesn't matter.
-#
-# ===================================================================
-# Commands have certain attributes and methods that facilitate parsing of
-# the arguments:
-#
-# self.line: The whole line that was written in the console.
-# self.args: A list of all (space-separated) arguments to the command.
-# self.quantifier: If this command was mapped to the key "X" and
-# the user pressed 6X, self.quantifier will be 6.
-# self.arg(n): The n-th argument, or an empty string if it doesn't exist.
-# self.rest(n): The n-th argument plus everything that followed. For example,
-# If the command was "search foo bar a b c", rest(2) will be "bar a b c"
-# self.start(n): The n-th argument and anything before it. For example,
-# If the command was "search foo bar a b c", rest(2) will be "bar a b c"
-#
-# ===================================================================
-# And this is a little reference for common ranger functions and objects:
-#
-# self.fm: A reference to the "fm" object which contains most information
-# about ranger.
-# self.fm.notify(string): Print the given string on the screen.
-# self.fm.notify(string, bad=True): Print the given string in RED.
-# self.fm.reload_cwd(): Reload the current working directory.
-# self.fm.env.cwd: The current working directory. (A File object.)
-# self.fm.env.cf: The current file. (A File object too.)
-# self.fm.env.cwd.get_selection(): A list of all selected files.
-# self.fm.execute_console(string): Execute the string as a ranger command.
-# self.fm.open_console(string): Open the console with the given string
-# already typed in for you.
-# self.fm.move(direction): Moves the cursor in the given direction, which
-# can be something like down=3, up=5, right=1, left=1, to=6, ...
-#
-# File objects (for example self.fm.env.cf) have these useful attributes and
-# methods:
-#
-# cf.path: The path to the file.
-# cf.basename: The base name only.
-# cf.load_content(): Force a loading of the directories content (which
-# obviously works with directories only)
-# cf.is_directory: True/False depending on whether it's a directory.
-#
-# For advanced commands it is unavoidable to dive a bit into the source code
-# of ranger.
-# ===================================================================
-
from ranger.api.commands import *
from ranger.ext.get_executables import get_executables
from ranger.core.runner import ALLOWED_FLAGS
@@ -93,8 +15,8 @@ class dd(Command):
When attempting to delete non-empty directories or multiple
marked files, it will require a confirmation: The last word in
the line has to start with a 'y'. This may look like:
- :dd yes
- :dd seriously? yeah!
+ :delete yes
+ :delete seriously? yeah!
"""
allow_abbrev = False
View
29 .config/ranger/options.py
@@ -1,21 +1,18 @@
-# -*- coding: utf-8 -*-
-# Copyright (C) 2009, 2010, 2011 Roman Zimbelmann <romanz@lavabit.com>
-# This configuration file is licensed under the same terms as ranger.
-# ===================================================================
-# This is the main configuration file of ranger. It consists of python
-# code, but fear not, you don't need any python knowledge for changing
-# the settings.
-#
-# Lines beginning with # are comments. To enable a line, remove the #.
-#
-# You can customize ranger in the file ~/.config/ranger/options.py.
-# It has the same syntax as this file. In fact, you can just copy this
-# file there with `ranger --copy-config=options' and make your modifications.
-# But make sure you update your configs when you update ranger.
-# ===================================================================
-
from ranger.api.options import *
+# Use that external preview script or display internal plain text previews?
+use_preview_script = True
+
+# Preview files on the rightmost column?
+# And collapse (shrink) the last column if there is nothing to preview?
+collapse_preview = False
+
+# Display the directory name in tabs?
+dirname_in_tabs = True
+
# Enable the mouse support?
mouse_enabled = False
+# Display the file size in the main column or status bar?
+display_size_in_main_column = True
+display_size_in_status_bar = True
View
75 .config/ranger/scope.sh
@@ -0,0 +1,75 @@
+#!/bin/bash
+# ranger supports enhanced previews. If the option "use_preview_script"
+# is set to True (by default it's False), this script will be called
+# and its output is displayed in ranger. ANSI color codes are supported.
+
+# NOTES: This script is considered a configuration file. If you upgrade
+# ranger, it will be left untouched. (You must update it yourself.)
+# Also, ranger disables STDIN here, so interactive scripts won't work properly
+
+# Meanings of exit codes:
+# code | meaning | action of ranger
+# -----+------------+-------------------------------------------
+# 0 | success | success. display stdout as preview
+# 1 | no preview | failure. display no preview at all
+# 2 | plain text | display the plain content of the file
+# 3 | fix width | success. Don't reload when width changes
+# 4 | fix height | success. Don't reload when height changes
+# 5 | fix both | success. Don't ever reload
+
+# Meaningful aliases for arguments:
+path="$1" # Full path of the selected file
+width="$2" # Width of the preview pane (number of fitting characters)
+height="$3" # Height of the preview pane (number of fitting characters)
+
+maxln=200 # Stop after $maxln lines. Can be used like ls | head -n $maxln
+
+# Find out something about the file:
+mimetype=$(file --mime-type -Lb "$path")
+extension=$(echo "$path" | grep '\.' | grep -o '[^.]\+$')
+
+# 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; }
+
+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;;
+ # 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
+ success && exit 5 || exit 2;;
+ # Ascii-previews of images:
+# image/*)
+# img2txt --gamma=0.6 --width="$width" "$path" && exit 4 || exit 1;;
+ # Display information about media files:
+# video/* | audio/*)
+ # Use sed to remove spaces so the output fits into the narrow window
+# mediainfo "$path" | sed 's/ \+:/: /;'
+# success && exit 5 || exit 1;;
+esac
+
+exit 1

0 comments on commit 6b2b316

Please sign in to comment.
Something went wrong with that request. Please try again.