about summary refs log tree commit diff stats
path: root/examples
diff options
context:
space:
mode:
authorNRK <nrk@disroot.org>2021-09-13 13:37:01 +0600
committerNRK <nrk@disroot.org>2021-09-13 13:37:01 +0600
commit776dc63983c2b957363dde16ca668de5144fcaee (patch)
tree229b9f6e784c9ae1db40ee9fd28823e860f2382f /examples
parent08e1a5b2279c69aedd06eaec20240c8216b9bdb8 (diff)
downloadranger-776dc63983c2b957363dde16ca668de5144fcaee.tar.gz
rework the script
- remove null seperator
- store the result of listfiles into a tmp file
- remove -m 1 from grep, it's not needed. (it also wasn't posix)
- remove dep on xargs
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/rifle_sxiv.sh9
1 files changed, 6 insertions, 3 deletions
diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh
index 10a473fc..68b6d21c 100755
--- a/examples/rifle_sxiv.sh
+++ b/examples/rifle_sxiv.sh
@@ -19,9 +19,11 @@
 # not work in dash and others), so we cannot store the result of listfiles to a
 # variable.
 
+tmp="/tmp/sxiv_rifle_$$"
+
 listfiles () {
     find -L "///${target%/*}" -maxdepth 1 -type f -iregex \
-      '.*\.\(jpe?g\|png\|gif\|webp\|tiff\|bmp\)$' -print0 | sort -z
+      '.*\.\(jpe?g\|png\|gif\|webp\|tiff\|bmp\)$' -print | sort | tee "$tmp"
 }
 
 is_img () {
@@ -39,10 +41,11 @@ case "$1" in
     *)  target="$PWD/$1" ;;
 esac
 
-is_img "$target" && count="$(listfiles | grep -m 1 -ZznF "$target")"
+trap "rm -f $tmp" EXIT
+is_img "$target" && count="$(listfiles | grep -nF "$target")"
 
 if [ -n "$count" ]; then
-    listfiles | xargs -0 sxiv -n "${count%%:*}" --
+    sxiv -i -n "${count%%:*}" -- < "$tmp"
 else
     sxiv -- "$@" # fallback
 fi