summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2013-03-06 17:21:53 +0100
committerhut <hut@lavabit.com>2013-03-06 17:21:53 +0100
commitc6217eca95ee932fcd90b0cb4be9d15fed5e0c3b (patch)
treeaeb856f85a5a13ff8b1996a8acfba85b4c616c6a
parentf7811dd4901a282bca4af9bb1b61e16ce8a6c35d (diff)
downloadranger-c6217eca95ee932fcd90b0cb4be9d15fed5e0c3b.tar.gz
Add setting "open_all_images", removing "sxiv_opens_all_images"
this is more general and can be adapted to work with more image viewers.
-rw-r--r--ranger/config/rc.conf6
-rw-r--r--ranger/container/settings.py2
-rw-r--r--ranger/core/fm.py41
3 files changed, 34 insertions, 15 deletions
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index 66f9c867..3611819a 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -41,9 +41,9 @@ 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
+# Open all images in this directory when running certain image viewers
+# like feh or sxiv?  You can still open selected files by marking them.
+set open_all_images 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 29dafc9a..23d20412 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -42,7 +42,7 @@ ALLOWED_SETTINGS = {
     'sort_reverse': bool,
     'sort': str,
     'status_bar_on_top': bool,
-    'sxiv_opens_all_files': bool,
+    'open_all_images': bool,
     'tilde_in_titlebar': bool,
     'unicode_ellipsis': bool,
     'update_title': bool,
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index 3bac283e..f0c97d16 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -116,21 +116,40 @@ 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
+        # This hook allows image viewers to open all images in the current
+        # directory, keeping the order of files the same as in ranger.
+        # The requirements to use it are:
+        # 1. set open_all_images to true
         # 2. ensure no files are marked
-        # 3. call rifle with a command that starts with "sxiv "
+        # 3. call rifle with a command that starts with "sxiv " or "feh "
         def sxiv_workaround_hook(command):
-            if self.settings.sxiv_opens_all_files and command[0:5] == "sxiv "\
-                    and len(self.thisdir.marked_items) == 0:
+            import re
+            from ranger.ext.shell_escape import shell_quote
+
+            if self.settings.open_all_images and \
+                    len(self.thisdir.marked_items) == 0 and \
+                    re.match(r'^(feh|sxiv) ', command):
+
                 images = [f.basename for f in self.thisdir.files if f.image]
+                escaped_filenames = " ".join(shell_quote(f) \
+                        for f in images if "\x00" not in f)
+
                 if images and self.thisfile.basename in images:
-                    number = images.index(self.thisfile.basename) + 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))
+                    new_command = None
+
+                    if command[0:5] == 'sxiv ':
+                        number = images.index(self.thisfile.basename) + 1
+                        new_command = command.replace("sxiv ",
+                                "sxiv -n %d " % number, 1)
+
+                    if command[0:4] == 'feh ':
+                        new_command = command.replace("feh ",
+                            "feh --start-at '%s' " % \
+                            shell_quote(self.thisfile.basename), 1)
+
+                    if new_command:
+                        command = "set -- %s; %s" % (escaped_filenames,
+                                new_command)
             return command
 
         self.rifle.hook_command_preprocessing = sxiv_workaround_hook