about summary refs log tree commit diff stats
path: root/examples/rifle_sxiv.sh
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 /examples/rifle_sxiv.sh
parent69950954a9f1041ec0f494571250f10ff2fb7c77 (diff)
downloadranger-b53a97ed7b7022ccf3cb3a91d2dbfd15e9352246.tar.gz
Fixed the sxiv workaround to handle spaces and be more POSIX compliant.
Diffstat (limited to 'examples/rifle_sxiv.sh')
-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
rtik.com> 2016-03-27 17:43:41 -0700 2812' href='/akkartik/mu/commit/html/053dilated_reagent.cc.html?h=hlt&id=a654e4ecace2d506d1b10f1dde2c287ebe84ef37'>a654e4ec ^
e6056999 ^
70f4e9b6 ^
76755b28 ^

a654e4ec ^





76755b28 ^

a654e4ec ^
76755b28 ^
c4f5d4cf ^

76755b28 ^


3e1349d2 ^
76755b28 ^

a654e4ec ^
76755b28 ^
db1f56c8 ^
3e1349d2 ^
db1f56c8 ^




d009e158 ^
3e1349d2 ^
d009e158 ^

a654e4ec ^
d009e158 ^


3e1349d2 ^
d009e158 ^



76755b28 ^


4690ce81 ^
db1f56c8 ^

4690ce81 ^
db1f56c8 ^
76755b28 ^



4690ce81 ^

a654e4ec ^
76755b28 ^
67db19a0 ^
4690ce81 ^
db1f56c8 ^
76755b28 ^




cd9bb850 ^
76755b28 ^

4690ce81 ^


4690ce81 ^

cd9bb850 ^



76755b28 ^


4690ce81 ^

cd9bb850 ^



76755b28 ^

4690ce81 ^

cd9bb850 ^



76755b28 ^


4690ce81 ^
76755b28 ^
d009e158 ^
76755b28 ^



0ca56ed8 ^
76755b28 ^



dcc060c7 ^
4690ce81 ^
2f02189d ^
dcc060c7 ^

4690ce81 ^
2f02189d ^
dcc060c7 ^


beea7ce2 ^






44c1aeef ^


dcc060c7 ^
4690ce81 ^
76755b28 ^
4690ce81 ^

beea7ce2 ^






44c1aeef ^
76755b28 ^

76755b28 ^





beea7ce2 ^




4690ce81 ^
76755b28 ^
4690ce81 ^
76755b28 ^





a654e4ec ^
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