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
|
|
|
|
#
|
|
|
|
# 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 \
|
|
|
|
'.*\(jpe?g\|bmp\|png\|gif\)$' -print0 | sort -z
|
|
|
|
}
|
|
|
|
|
|
|
|
sxiv_view_dir() {
|
|
|
|
target="$(abspath "$1")"
|
|
|
|
count="$(listimages | grep -a -m 1 -ZznF "$target" | cut -d: -f1)"
|
|
|
|
|
|
|
|
if [ -n "$count" ]; then
|
|
|
|
listimages | xargs -0 sxiv -n "$count" --
|
|
|
|
else
|
|
|
|
sxiv -- "$@" # fallback
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-01-02 18:57:28 +00:00
|
|
|
if [ -z "$1" ] || ! [ -s "$1" ]; then
|
|
|
|
printf "empty file"
|
|
|
|
read -r _
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if command -v sxiv >/dev/null 2>&1; then
|
|
|
|
if [ -f "$1" ]; then
|
2020-03-03 00:46:52 +00:00
|
|
|
sxiv_view_dir "$1" >/dev/null 2>&1 &
|
2020-01-02 18:57:28 +00:00
|
|
|
elif [ -d "$1" ] || [ -h "$1" ]; then
|
2020-03-03 00:46:52 +00:00
|
|
|
sxiv -qt "$1" >/dev/null 2>&1 &
|
2020-01-02 18:57:28 +00:00
|
|
|
fi
|
|
|
|
elif command -v viu >/dev/null 2>&1; then
|
|
|
|
viu -n "$1" | less -R
|
|
|
|
else
|
|
|
|
printf "install sxiv or viu"
|
|
|
|
read -r _
|
|
|
|
exit 2
|
|
|
|
fi
|