summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorPierre Neidhardt <ambrevar@gmail.com>2013-03-05 15:43:04 +0100
committerPierre Neidhardt <ambrevar@gmail.com>2013-03-05 15:43:04 +0100
commitb53a97ed7b7022ccf3cb3a91d2dbfd15e9352246 (patch)
tree89d8fe1c631e81268a42f9cdf5f2c4fcd6a347aa
parent69950954a9f1041ec0f494571250f10ff2fb7c77 (diff)
downloadranger-b53a97ed7b7022ccf3cb3a91d2dbfd15e9352246.tar.gz
Fixed the sxiv workaround to handle spaces and be more POSIX compliant.
-rwxr-xr-xexamples/rifle_sxiv.sh28
1 files changed, 21 insertions, 7 deletions
diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh
index 60cc8d82..b5e2a095 100755
--- a/examples/rifle_sxiv.sh
+++ b/examples/rifle_sxiv.sh
@@ -1,30 +1,44 @@
 #!/bin/sh
 # Compatible with ranger 1.6.*
 #
-# This script searches image files in a directory, opens them all with sxiv
-# and sets the first argument to the first image displayed by sxiv.
+# This script searches image files in a directory, opens them all with sxiv and
+# sets the first argument to the first image displayed by sxiv.
 #
 # This is supposed to be used in rifle.conf as a workaround for the fact that
-# sxiv takes no file name arguments for the first image, just the number.
-# Copy this file somewhere into your $PATH and add this at the top of rifle.conf:
+# sxiv takes no file name arguments for the first image, just the number.  Copy
+# this file somewhere into your $PATH and add this at the top of rifle.conf:
 #
 #   mime ^image, has sxiv, X, flag f = path/to/this/script -- "$@"
 #
+# Implementation notes: this script is quite slow because of POSIX limitations
+# and portability concerns. First calling the shell function 'abspath' is
+# quicker than calling 'realpath' because it would fork a whole process, which
+# is slow. Second, we need to append a file list to sxiv, which can only be done
+# properly in two ways: arrays (which are not POSIX) or \0 sperated
+# strings. Unfortunately, assigning \0 to a variable is not POSIX either (will
+# not work in dash and others), so we cannot store the result of listfiles to a
+# variable.
+
+if [ $# -eq 0 ]; then
+    echo "Usage: ${0##*/} PICTURES"
+    exit
+fi
 
 [ "$1" == '--' ] && shift
 
-function abspath {
+abspath () {
     case "$1" in
         /*) printf "%s\n" "$1";;
         *)  printf "%s\n" "$PWD/$1";;
     esac
 }
-function listfiles {
+
+listfiles () {
     find -L "$(dirname "$target")" -maxdepth 1 -type f -iregex \
       '.*\(jpe?g\|bmp\|png\|gif\)$' -print0 | sort -z
 }
 
-target="$(abspath $1)"
+target="$(abspath "$1")"
 count="$(listfiles | grep -m 1 -Zznx "$target" | cut -d: -f1)"
 
 if [ -n "$count" ]; then
id=2fb656b4f466f85437c268da9e05b270d020b964'>^
8bd3c2b5 ^
9511ff5c ^



9511ff5c ^









1afc8828 ^
9511ff5c ^
1afc8828 ^
9511ff5c ^


8bd3c2b5 ^
9511ff5c ^



9511ff5c ^




a3bfbb99 ^
22254896 ^
9511ff5c ^




22254896 ^
9511ff5c ^




967d11f1 ^
6c7f7abd ^
b22fa8af ^


d4a7c535 ^






6c7f7abd ^
d4a7c535 ^



b22fa8af ^





8bd3c2b5 ^
b22fa8af ^



690fa191 ^
eb40c70e ^
8bd3c2b5 ^
9511ff5c ^




8bd3c2b5 ^
9511ff5c ^







8bd3c2b5 ^
9511ff5c ^




8bd3c2b5 ^
9511ff5c ^



9511ff5c ^










1afc8828 ^
9511ff5c ^



1afc8828 ^
9511ff5c ^


8bd3c2b5 ^
9511ff5c ^



9511ff5c ^




8bd3c2b5 ^
9511ff5c ^





8bd3c2b5 ^
9511ff5c ^




8bd3c2b5 ^
9511ff5c ^





8bd3c2b5 ^
9511ff5c ^




8bd3c2b5 ^
9511ff5c ^





8bd3c2b5 ^
9511ff5c ^





8bd3c2b5 ^
9511ff5c ^





8bd3c2b5 ^
9511ff5c ^




8bd3c2b5 ^
9511ff5c ^





8bd3c2b5 ^
9511ff5c ^




8bd3c2b5 ^
9511ff5c ^







8bd3c2b5 ^
9511ff5c ^










































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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
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