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
^
34a60763 ^
f07bb12f ^

34a60763 ^
f07bb12f ^
34a60763 ^
f07bb12f ^





34a60763 ^
f07bb12f ^





34a60763 ^
f07bb12f ^

34a60763 ^
f07bb12f ^

34a60763 ^
f07bb12f ^



34a60763 ^
f07bb12f ^
34a60763 ^
f07bb12f ^
34a60763 ^
f07bb12f ^






f07bb12f ^

34a60763 ^
f07bb12f ^
34a60763 ^





f07bb12f ^
34a60763 ^

f07bb12f ^
34a60763 ^
f07bb12f ^
34a60763 ^





f07bb12f ^
34a60763 ^

f07bb12f ^
34a60763 ^





f07bb12f ^




34a60763 ^

f07bb12f ^
34a60763 ^

f07bb12f ^










34a60763 ^
f07bb12f ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204