From e3a98d51be122294d5792347358f9d6f3e17a8c1 Mon Sep 17 00:00:00 2001 From: NRK Date: Sun, 8 Aug 2021 16:37:53 +0600 Subject: rifle_sxiv: performance improvement --- examples/rifle_sxiv.sh | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index 0bdd892d..866dd730 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -11,7 +11,7 @@ # 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 +# and portability concerns. First, using case statement to get absolute path 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 @@ -19,26 +19,18 @@ # 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 - -abspath () { - case "$1" in - /*) printf "%s\n" "$1";; - *) printf "%s\n" "$PWD/$1";; - esac -} - listfiles () { - find -L "$(dirname "$target")" -maxdepth 1 -type f -iregex \ + find -L "${target%/*}" -maxdepth 1 -type f -iregex \ '.*\(jpe?g\|bmp\|png\|gif\)$' -print0 | sort -z } -target="$(abspath "$1")" +[ "$1" = '--' ] && shift +case "$1" in + "") echo "Usage: ${0##*/} PICTURES" >/dev/stderr && exit ;; + /*) target="$1" ;; + *) target="$PWD/$1" ;; +esac + count="$(listfiles | grep -m 1 -ZznF "$target" | cut -d: -f1)" if [ -n "$count" ]; then -- cgit 1.4.1-2-gfad0 From dc791089695a110623d9ca9ec84c9c39b6e31182 Mon Sep 17 00:00:00 2001 From: NRK Date: Sun, 8 Aug 2021 17:22:34 +0600 Subject: rifle_sxiv: add webp to listfiles() --- examples/rifle_sxiv.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index 866dd730..ba429e8d 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -21,7 +21,7 @@ listfiles () { find -L "${target%/*}" -maxdepth 1 -type f -iregex \ - '.*\(jpe?g\|bmp\|png\|gif\)$' -print0 | sort -z + '.*\(jpe?g\|bmp\|png\|gif\|webp\)$' -print0 | sort -z } [ "$1" = '--' ] && shift -- cgit 1.4.1-2-gfad0 From c47c0f3216fddedfb8099adbb98eece41f8ec040 Mon Sep 17 00:00:00 2001 From: NRK Date: Sun, 15 Aug 2021 03:50:33 +0600 Subject: fix edge case when file is in root --- examples/rifle_sxiv.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index ba429e8d..d0b5058f 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -20,7 +20,7 @@ # variable. listfiles () { - find -L "${target%/*}" -maxdepth 1 -type f -iregex \ + find -L "///${target%/*}" -maxdepth 1 -type f -iregex \ '.*\(jpe?g\|bmp\|png\|gif\|webp\)$' -print0 | sort -z } -- cgit 1.4.1-2-gfad0 From 51d3afc62142d2ead59173200f3d0b03a545a5ea Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 27 Aug 2021 15:08:42 +0600 Subject: sxiv-rifle: don't grep if $target is not a file --- examples/rifle_sxiv.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index d0b5058f..5fab6b78 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -31,7 +31,7 @@ case "$1" in *) target="$PWD/$1" ;; esac -count="$(listfiles | grep -m 1 -ZznF "$target" | cut -d: -f1)" +[ -f "$target" ] && count="$(listfiles | grep -m 1 -ZznF "$target" | cut -d: -f1)" if [ -n "$count" ]; then listfiles | xargs -0 sxiv -n "$count" -- -- cgit 1.4.1-2-gfad0 From d39308d95cc34b05f91e5f0386f5a9b69ed525fb Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 27 Aug 2021 15:11:58 +0600 Subject: sxiv-rifle: use parameter expansion instead of cut --- examples/rifle_sxiv.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index 5fab6b78..5b096eaa 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -31,10 +31,10 @@ case "$1" in *) target="$PWD/$1" ;; esac -[ -f "$target" ] && count="$(listfiles | grep -m 1 -ZznF "$target" | cut -d: -f1)" +[ -f "$target" ] && count="$(listfiles | grep -m 1 -ZznF "$target")" if [ -n "$count" ]; then - listfiles | xargs -0 sxiv -n "$count" -- + listfiles | xargs -0 sxiv -n "${count%%:*}" -- else sxiv -- "$@" # fallback fi -- cgit 1.4.1-2-gfad0 From c09d4a846ccf635579ef3cb3e55d20478fb07438 Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 27 Aug 2021 15:35:43 +0600 Subject: sxiv-rifle: don't grep non img extension files --- examples/rifle_sxiv.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index 5b096eaa..15fc914f 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -24,6 +24,13 @@ listfiles () { '.*\(jpe?g\|bmp\|png\|gif\|webp\)$' -print0 | sort -z } +ispic () { + case "${1##*.}" in + "jpg"|"jpeg"|"bmp"|"png"|"gif"|"webp") return 0 ;; + *) return 1 ;; + esac +} + [ "$1" = '--' ] && shift case "$1" in "") echo "Usage: ${0##*/} PICTURES" >/dev/stderr && exit ;; @@ -31,7 +38,7 @@ case "$1" in *) target="$PWD/$1" ;; esac -[ -f "$target" ] && count="$(listfiles | grep -m 1 -ZznF "$target")" +ispic "$target" && count="$(listfiles | grep -m 1 -ZznF "$target")" if [ -n "$count" ]; then listfiles | xargs -0 sxiv -n "${count%%:*}" -- -- cgit 1.4.1-2-gfad0 From b9e627547757ba04b6961e2aaf569f1f3102a1eb Mon Sep 17 00:00:00 2001 From: N-R-K <79544946+N-R-K@users.noreply.github.com> Date: Fri, 27 Aug 2021 14:12:37 +0000 Subject: change func name to is_img Co-authored-by: toonn --- examples/rifle_sxiv.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index 15fc914f..6d87d2ad 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -24,7 +24,7 @@ listfiles () { '.*\(jpe?g\|bmp\|png\|gif\|webp\)$' -print0 | sort -z } -ispic () { +is_img () { case "${1##*.}" in "jpg"|"jpeg"|"bmp"|"png"|"gif"|"webp") return 0 ;; *) return 1 ;; @@ -38,7 +38,7 @@ case "$1" in *) target="$PWD/$1" ;; esac -ispic "$target" && count="$(listfiles | grep -m 1 -ZznF "$target")" +is_img "$target" && count="$(listfiles | grep -m 1 -ZznF "$target")" if [ -n "$count" ]; then listfiles | xargs -0 sxiv -n "${count%%:*}" -- -- cgit 1.4.1-2-gfad0 From ed06faa056bcdbb32881958b99151896dfe41348 Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 27 Aug 2021 20:32:11 +0600 Subject: sxiv-rifle: handle unresolved `~` --- examples/rifle_sxiv.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index 6d87d2ad..8388fa10 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -35,6 +35,7 @@ is_img () { case "$1" in "") echo "Usage: ${0##*/} PICTURES" >/dev/stderr && exit ;; /*) target="$1" ;; + "~"/*) target="$HOME/${1#"~"/}" ;; *) target="$PWD/$1" ;; esac -- cgit 1.4.1-2-gfad0 From 13ca30d4d63023fe1dd9dceb356238583595e667 Mon Sep 17 00:00:00 2001 From: N-R-K <79544946+N-R-K@users.noreply.github.com> Date: Fri, 27 Aug 2021 14:38:08 +0000 Subject: change order of bmp Co-authored-by: toonn --- examples/rifle_sxiv.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index 8388fa10..f29c68a8 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -21,12 +21,12 @@ listfiles () { find -L "///${target%/*}" -maxdepth 1 -type f -iregex \ - '.*\(jpe?g\|bmp\|png\|gif\|webp\)$' -print0 | sort -z + '.*\(jpe?g\|png\|gif\|webp\|bmp\)$' -print0 | sort -z } is_img () { case "${1##*.}" in - "jpg"|"jpeg"|"bmp"|"png"|"gif"|"webp") return 0 ;; + "jpg"|"jpeg"|"png"|"gif"|"webp"|"bmp") return 0 ;; *) return 1 ;; esac } -- cgit 1.4.1-2-gfad0 From 1587046cd89cb2741474f0cc256285302cc75d19 Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 27 Aug 2021 20:39:01 +0600 Subject: sxiv-rifle: add tiff support --- examples/rifle_sxiv.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index f29c68a8..ba232916 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -21,12 +21,12 @@ listfiles () { find -L "///${target%/*}" -maxdepth 1 -type f -iregex \ - '.*\(jpe?g\|png\|gif\|webp\|bmp\)$' -print0 | sort -z + '.*\(jpe?g\|png\|gif\|webp\|tiff\|bmp\)$' -print0 | sort -z } is_img () { case "${1##*.}" in - "jpg"|"jpeg"|"png"|"gif"|"webp"|"bmp") return 0 ;; + "jpg"|"jpeg"|"png"|"gif"|"webp"|"tiff"|"bmp") return 0 ;; *) return 1 ;; esac } -- cgit 1.4.1-2-gfad0 From 08e1a5b2279c69aedd06eaec20240c8216b9bdb8 Mon Sep 17 00:00:00 2001 From: NRK Date: Wed, 8 Sep 2021 03:51:51 +0600 Subject: sxiv-rifle: only list extensions --- examples/rifle_sxiv.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index ba232916..10a473fc 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -21,7 +21,7 @@ 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\)$' -print0 | sort -z } is_img () { -- cgit 1.4.1-2-gfad0 From 776dc63983c2b957363dde16ca668de5144fcaee Mon Sep 17 00:00:00 2001 From: NRK Date: Mon, 13 Sep 2021 13:37:01 +0600 Subject: 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 --- examples/rifle_sxiv.sh | 9 ++++++--- 1 file 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 -- cgit 1.4.1-2-gfad0 From 8ca27cd891e7fb35b0c0f5e498e8f886bd053b1a Mon Sep 17 00:00:00 2001 From: NRK Date: Mon, 13 Sep 2021 18:19:44 +0600 Subject: cleanups - remove invalid/old comment - use func args instead of global var - offload image loading into it's own function --- examples/rifle_sxiv.sh | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index 68b6d21c..b8a51a64 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -10,19 +10,11 @@ # # 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, using case statement to get absolute path 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. tmp="/tmp/sxiv_rifle_$$" listfiles () { - find -L "///${target%/*}" -maxdepth 1 -type f -iregex \ + find -L "///${1%/*}" -maxdepth 1 -type f -iregex \ '.*\.\(jpe?g\|png\|gif\|webp\|tiff\|bmp\)$' -print | sort | tee "$tmp" } @@ -33,19 +25,21 @@ is_img () { esac } +open_img () { + is_img "$1" || exit 1 + trap 'rm -f $tmp' EXIT + count="$(listfiles "$1" | grep -nF "$1")" + if [ -n "$count" ]; then + sxiv -i -n "${count%%:*}" -- < "$tmp" + else + sxiv -- "$@" # fallback + fi +} + [ "$1" = '--' ] && shift case "$1" in - "") echo "Usage: ${0##*/} PICTURES" >/dev/stderr && exit ;; - /*) target="$1" ;; - "~"/*) target="$HOME/${1#"~"/}" ;; - *) target="$PWD/$1" ;; + "") echo "Usage: ${0##*/} PICTURES" >&2; exit 1 ;; + /*) open_img "$1" ;; + "~"/*) open_img "$HOME/${1#"~"/}" ;; + *) open_img "$PWD/$1" ;; esac - -trap "rm -f $tmp" EXIT -is_img "$target" && count="$(listfiles | grep -nF "$target")" - -if [ -n "$count" ]; then - sxiv -i -n "${count%%:*}" -- < "$tmp" -else - sxiv -- "$@" # fallback -fi -- cgit 1.4.1-2-gfad0 From 6b674f2c89247c35065b2141c48a38ebeb4e55ad Mon Sep 17 00:00:00 2001 From: NRK Date: Mon, 13 Sep 2021 23:09:25 +0600 Subject: use more posix complaint flags --- examples/rifle_sxiv.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index b8a51a64..ec55b249 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -14,8 +14,10 @@ tmp="/tmp/sxiv_rifle_$$" listfiles () { - find -L "///${1%/*}" -maxdepth 1 -type f -iregex \ - '.*\.\(jpe?g\|png\|gif\|webp\|tiff\|bmp\)$' -print | sort | tee "$tmp" + find -L "///${1%/*}" \( ! -path "///${1%/*}" -prune \) -type f \ + \( -name '*.jpg' -o -name '*.jpeg' -o -name '*.png' -o -name '*.gif' \ + -o -name '*.webp' -o -name '*.tiff' -o -name '*.bmp' \) -print | + sort | tee "$tmp" } is_img () { -- cgit 1.4.1-2-gfad0 From a9101682c1a6efb0a06ef1ccc334e3aa8e75bf1b Mon Sep 17 00:00:00 2001 From: NRK Date: Mon, 13 Sep 2021 23:27:55 +0600 Subject: switch to -iname --- examples/rifle_sxiv.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index ec55b249..7148d92c 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -15,8 +15,8 @@ tmp="/tmp/sxiv_rifle_$$" listfiles () { find -L "///${1%/*}" \( ! -path "///${1%/*}" -prune \) -type f \ - \( -name '*.jpg' -o -name '*.jpeg' -o -name '*.png' -o -name '*.gif' \ - -o -name '*.webp' -o -name '*.tiff' -o -name '*.bmp' \) -print | + \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.gif' \ + -o -iname '*.webp' -o -iname '*.tiff' -o -iname '*.bmp' \) -print | sort | tee "$tmp" } -- cgit 1.4.1-2-gfad0 From 8e4d2d396b9876c240c3a4d7a82296a57a358706 Mon Sep 17 00:00:00 2001 From: NRK Date: Sat, 18 Sep 2021 23:53:53 +0600 Subject: use grep -iE instead of -iname --- examples/rifle_sxiv.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index 7148d92c..45a13f28 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -14,9 +14,8 @@ tmp="/tmp/sxiv_rifle_$$" listfiles () { - find -L "///${1%/*}" \( ! -path "///${1%/*}" -prune \) -type f \ - \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.gif' \ - -o -iname '*.webp' -o -iname '*.tiff' -o -iname '*.bmp' \) -print | + find -L "///${1%/*}" \( ! -path "///${1%/*}" -prune \) -type f | + grep -iE '\.(jpe?g|png|gif|webp|tiff|bmp)$' | sort | tee "$tmp" } -- cgit 1.4.1-2-gfad0 From d1b803cdf3657e7bfa11f2aa102db8b565ff1f98 Mon Sep 17 00:00:00 2001 From: NRK Date: Sun, 19 Sep 2021 00:10:56 +0600 Subject: -print explicitly for posix compliance --- examples/rifle_sxiv.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index 45a13f28..6c1685be 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -14,7 +14,7 @@ tmp="/tmp/sxiv_rifle_$$" listfiles () { - find -L "///${1%/*}" \( ! -path "///${1%/*}" -prune \) -type f | + find -L "///${1%/*}" \( ! -path "///${1%/*}" -prune \) -type f -print | grep -iE '\.(jpe?g|png|gif|webp|tiff|bmp)$' | sort | tee "$tmp" } -- cgit 1.4.1-2-gfad0 From 0d783e17a461da481a4803e3cf970a15f1500bf5 Mon Sep 17 00:00:00 2001 From: NRK Date: Sun, 19 Sep 2021 01:23:05 +0600 Subject: add an implementation note --- examples/rifle_sxiv.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index 6c1685be..35c65da9 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -10,6 +10,10 @@ # # mime ^image, has sxiv, X, flag f = path/to/this/script -- "$@" # +# Implementation note: the script tries to be POSIX compliant both in terms of +# shell syntax and calls being made to external utilities, such as grep or find. +# This makes it portable across many unix like systems, although it may not be +# the cleanest or fastest approach. tmp="/tmp/sxiv_rifle_$$" -- cgit 1.4.1-2-gfad0 From d728452b0ffdb56de3ae642b848477a48f290740 Mon Sep 17 00:00:00 2001 From: NRK Date: Sun, 19 Sep 2021 01:30:12 +0600 Subject: add more detailed implementation note --- examples/rifle_sxiv.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index 35c65da9..f65524a8 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -14,6 +14,20 @@ # shell syntax and calls being made to external utilities, such as grep or find. # This makes it portable across many unix like systems, although it may not be # the cleanest or fastest approach. +# +# First, using case statement to get absolute path 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 three 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. +# +# The third approach is to store the result to a tmpfile and using `-i` to feed +# the list to sxiv. This is the fastest approach since we won't have to call +# listfiles twice. + tmp="/tmp/sxiv_rifle_$$" -- cgit 1.4.1-2-gfad0 From 4451a87a2bf9b95afd566ddcaaa7ba548d1ec8dc Mon Sep 17 00:00:00 2001 From: NRK Date: Sun, 19 Sep 2021 01:54:00 +0600 Subject: dont hardcode /tmp --- examples/rifle_sxiv.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index f65524a8..e5b14db8 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -29,7 +29,8 @@ # listfiles twice. -tmp="/tmp/sxiv_rifle_$$" +TMPDIR="${TMPDIR:-/tmp}" +tmp="$TMPDIR/sxiv_rifle_$$" listfiles () { find -L "///${1%/*}" \( ! -path "///${1%/*}" -prune \) -type f -print | -- cgit 1.4.1-2-gfad0 From 72a0cfefcfb349627f0d278cb1bc295f0a242bbc Mon Sep 17 00:00:00 2001 From: NRK Date: Sun, 19 Sep 2021 01:59:29 +0600 Subject: cleanup the comment --- examples/rifle_sxiv.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index e5b14db8..82c65f6c 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -19,10 +19,9 @@ # '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 three 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. +# properly in three ways: arrays (which are not POSIX). +# \0 separated strings; but assigning \0 to a variable is not POSIX either +# so we cannot store the result of listfiles to a variable. # # The third approach is to store the result to a tmpfile and using `-i` to feed # the list to sxiv. This is the fastest approach since we won't have to call -- cgit 1.4.1-2-gfad0