Community patches, scripts, tips and tricks for nsxiv.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.3 KiB

#!/usr/bin/env sh
set -e
OPENER="${OPENER:-"xdg-open"}"
CACHEDIR="${NSXIV_THUMB_CACHE_DIR:-"${XDG_CACHE_HOME:-"$HOME/.cache"}/nsxiv-extra/nsxiv-thumb"}"
# extension of thumbnails. can be jpg or png.
EXT="jpg"
[ "$#" -gt 0 ] && {
cd "$1" || exit 1
}
mkdir -p -- "$CACHEDIR"
! command -v mktemp > /dev/null 2>&1 \
|| ! tmpdir="$(mktemp -d)" \
|| [ -z "$tmpdir" ] \
&& {
tmpdir="${TMPDIR:-/tmp}/nsxiv_$$"
mkdir -p -- "$tmpdir"
}
trap 'rm -rf -- "$tmpdir"' TERM INT EXIT HUP
find '.' \( -type f -o -type l \) -print \
| while IFS= read -r file; do
file="${file##./}"
[ "$file" != "${file##*/}" ] && continue
realpath="$(stat -f "%R" -- "$file")"
case "$(file -b --mime-type -- "$realpath")" in
video/*) :;;
*) exit 0;;
esac
hash="$(stat -f "%T%i%N%z%B%m" -- "$realpath" | md5 | cut -d" " -f1)"
thumbfl="$CACHEDIR/$hash.$EXT"
[ -f "$thumbfl" ] || ffmpegthumbnailer -i "$file" -o "$thumbfl" -m -s 384 2> /dev/null
cp -- "$thumbfl" "$tmpdir/$file.$EXT"
done
{ nsxiv -otp -- "$tmpdir"; rm -rf -- "${tmpdir:?}" > /dev/null; } \
| sed "s|\.$EXT$||;s|^.*/||" \
| sort \
| while IFS= read -r file; do
"$OPENER" ./"$file"
done