summaryrefslogtreecommitdiffstats
path: root/examples
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
parent69950954a9f1041ec0f494571250f10ff2fb7c77 (diff)
downloadranger-b53a97ed7b7022ccf3cb3a91d2dbfd15e9352246.tar.gz
Fixed the sxiv workaround to handle spaces and be more POSIX compliant.
Diffstat (limited to 'examples')
-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