about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425