summary refs log tree commit diff stats
path: root/examples/rifle_sxiv.sh
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-08-06 06:32:04 +0200
committerhut <hut@lavabit.com>2012-08-06 06:39:26 +0200
commit796074b541aaca459c594fe517c11d275778eef6 (patch)
tree0cc5c6450625a97a3375d6856b4ef07ca581ecdf /examples/rifle_sxiv.sh
parent13cb3fc49c07ba45f12508000ac615ff2e9b3e23 (diff)
downloadranger-796074b541aaca459c594fe517c11d275778eef6.tar.gz
added the examples from the man page to the examples directory
I guess a whole directory for examples scales better than having them in
the man page.
Diffstat (limited to 'examples/rifle_sxiv.sh')
-rwxr-xr-xexamples/rifle_sxiv.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh
new file mode 100755
index 00000000..5eb52fc0
--- /dev/null
+++ b/examples/rifle_sxiv.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+#
+# 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:
+#
+#   mime ^image, has sxiv, X, flag f = path/to/this/script -- "$@"
+#
+
+[ "$1" == '--' ] && shift
+target="$(realpath -s "$1")"
+function listfiles {
+    find "$(dirname "$target")" -maxdepth 1 -type f -iregex \
+      '.*\(jpe?g\|bmp\|png\|gif\)$' -print0 | sort -z
+}
+
+count="$(listfiles | grep -m 1 -Zznx "$target" | cut -d: -f1)"
+
+if [ -n "$count" ]; then
+    listfiles | xargs -0 sxiv -n "$count" --
+else
+    sxiv -- "$@" # fallback
+fi