From 50f6b42565ebbf957179acbcdbc5ef1d553a9705 Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 5 Mar 2013 20:01:06 +0100 Subject: added a rifle hook for better sxiv integration --- ranger/config/rc.conf | 4 ++++ ranger/container/settings.py | 1 + ranger/core/fm.py | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf index db52a78f..66f9c867 100644 --- a/ranger/config/rc.conf +++ b/ranger/config/rc.conf @@ -41,6 +41,10 @@ set preview_script ~/.config/ranger/scope.sh # Use the external preview script or display simple plain text previews? set use_preview_script true +# Open all images in this directory when running sxiv? You can still open +# selected files by marking them. +set sxiv_opens_all_files true + # Be aware of version control systems and display information. set vcs_aware false diff --git a/ranger/container/settings.py b/ranger/container/settings.py index d0b4be8d..29dafc9a 100644 --- a/ranger/container/settings.py +++ b/ranger/container/settings.py @@ -42,6 +42,7 @@ ALLOWED_SETTINGS = { 'sort_reverse': bool, 'sort': str, 'status_bar_on_top': bool, + 'sxiv_opens_all_files': bool, 'tilde_in_titlebar': bool, 'unicode_ellipsis': bool, 'update_title': bool, diff --git a/ranger/core/fm.py b/ranger/core/fm.py index 0a18e8d3..d6d830f6 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -116,6 +116,25 @@ class FM(Actions, SignalDispatcher): self.ui.initialize() if 'f' not in flags else None self.rifle.hook_logger = self.notify + # This hook allows the program sxiv to open all images in the current + # directory. Requirements to use it: + # 1. set sxiv_opens_all_files to true + # 2. ensure no files are marked + # 3. call rifle with a command that starts with "sxiv " + def sxiv_workaround_hook(command): + if self.settings.sxiv_opens_all_files and command[0:5] == "sxiv "\ + and len(self.thisdir.marked_items) == 0: + images = [f.path for f in self.thisdir.files if f.image] + if images and self.thisfile.path in images: + number = images.index(self.thisfile.path) + 1 + escaped_filenames = "' '".join(f.replace("'", + "'\\\''") for f in images if "\x00" not in f) + command = "set -- '%s'; %s" % (escaped_filenames, + command.replace("sxiv ", "sxiv -n %d " % number, 1)) + return command + + self.rifle.hook_command_preprocessing = sxiv_workaround_hook + def mylogfunc(text): self.notify(text, bad=True) self.run = Runner(ui=self.ui, logfunc=mylogfunc, fm=self) -- cgit 1.4.1-2-gfad0