2020-01-02 18:57:28 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
# Description: Open images in hovered directory and thumbnails
|
|
|
|
# open hovered image in sxiv or viu and browse other images in the directory
|
2020-06-10 20:19:40 +00:00
|
|
|
# Dependencies: imv (https://github.com/eXeC64/imv) or,
|
|
|
|
# sxiv (https://github.com/muennich/sxiv) or,
|
|
|
|
# viu (https://github.com/atanunq/viu), less
|
2020-01-02 18:57:28 +00:00
|
|
|
#
|
|
|
|
# Shell: POSIX compliant
|
|
|
|
# Author: Arun Prakash Jana
|
|
|
|
|
2020-03-03 00:46:52 +00:00
|
|
|
abspath() {
|
|
|
|
case "$1" in
|
|
|
|
/*) printf "%s\n" "$1";;
|
|
|
|
*) printf "%s\n" "$PWD/$1";;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
listimages() {
|
|
|
|
find -L "$(dirname "$target")" -maxdepth 1 -type f -iregex \
|
2021-04-20 01:00:30 +00:00
|
|
|
'.*\(jpe?g\|bmp\|webp\|ico\|svg\|png\|gif\)$' -print0 | sort -z
|
2020-03-03 00:46:52 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 20:19:40 +00:00
|
|
|
view_dir() {
|
|
|
|
target="$(abspath "$2")"
|
2020-03-03 00:46:52 +00:00
|
|
|
count="$(listimages | grep -a -m 1 -ZznF "$target" | cut -d: -f1)"
|
|
|
|
|
|
|
|
if [ -n "$count" ]; then
|
2020-09-15 02:59:50 +00:00
|
|
|
if [ "$1" = 'sxiv' ]; then
|
|
|
|
listimages | xargs -0 "$1" -an "$count" --
|
|
|
|
else
|
|
|
|
listimages | xargs -0 "$1" -n "$count" --
|
|
|
|
fi
|
2020-03-03 00:46:52 +00:00
|
|
|
else
|
2020-06-10 20:19:40 +00:00
|
|
|
shift
|
|
|
|
"$1" -- "$@" # fallback
|
2020-03-03 00:46:52 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-01-02 18:57:28 +00:00
|
|
|
if [ -z "$1" ] || ! [ -s "$1" ]; then
|
|
|
|
printf "empty file"
|
|
|
|
read -r _
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-08-20 09:21:26 +00:00
|
|
|
if uname | grep -q "Darwin"; then
|
|
|
|
if [ -f "$1" ]; then
|
|
|
|
open "$1" >/dev/null 2>&1 &
|
|
|
|
fi
|
2020-08-29 22:56:55 +00:00
|
|
|
# `imvr` is often callable as `imv` on Linux distros
|
|
|
|
# You might need to change the reference below
|
|
|
|
elif which imvr >/dev/null 2>&1; then
|
2020-01-02 18:57:28 +00:00
|
|
|
if [ -f "$1" ]; then
|
2020-06-10 20:19:40 +00:00
|
|
|
view_dir imvr "$1" >/dev/null 2>&1 &
|
|
|
|
elif [ -d "$1" ] || [ -h "$1" ]; then
|
|
|
|
imvr "$1" >/dev/null 2>&1 &
|
|
|
|
fi
|
2020-08-29 22:56:55 +00:00
|
|
|
elif which sxiv >/dev/null 2>&1; then
|
2020-06-10 20:19:40 +00:00
|
|
|
if [ -f "$1" ]; then
|
|
|
|
view_dir sxiv "$1" >/dev/null 2>&1 &
|
2020-01-02 18:57:28 +00:00
|
|
|
elif [ -d "$1" ] || [ -h "$1" ]; then
|
2020-09-14 17:01:32 +00:00
|
|
|
sxiv -aqt "$1" >/dev/null 2>&1 &
|
2020-01-02 18:57:28 +00:00
|
|
|
fi
|
2020-08-29 22:56:55 +00:00
|
|
|
elif which viu >/dev/null 2>&1; then
|
2020-01-02 18:57:28 +00:00
|
|
|
viu -n "$1" | less -R
|
|
|
|
else
|
2020-08-29 22:56:55 +00:00
|
|
|
printf "Please install imv/sxiv/viu and check their callable names match the plugin source"
|
2020-01-02 18:57:28 +00:00
|
|
|
read -r _
|
|
|
|
exit 2
|
|
|
|
fi
|