mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
1afdd48f5d
* nuke: use macOS open when GUI enabled * nuke: use is_mac function to test for macOS This is consistent with how the imgur plugin does detection. * Add macOS open command to plugins * pskill: only execute if input is non-empty
65 lines
1.6 KiB
Bash
Executable file
65 lines
1.6 KiB
Bash
Executable file
#!/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
|
|
# Dependencies: imv (https://github.com/eXeC64/imv) or,
|
|
# sxiv (https://github.com/muennich/sxiv) or,
|
|
# viu (https://github.com/atanunq/viu), less
|
|
#
|
|
# Shell: POSIX compliant
|
|
# Author: Arun Prakash Jana
|
|
|
|
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\|webp\|png\|gif\)$' -print0 | sort -z
|
|
}
|
|
|
|
view_dir() {
|
|
target="$(abspath "$2")"
|
|
count="$(listimages | grep -a -m 1 -ZznF "$target" | cut -d: -f1)"
|
|
|
|
if [ -n "$count" ]; then
|
|
listimages | xargs -0 "$1" -n "$count" --
|
|
else
|
|
shift
|
|
"$1" -- "$@" # fallback
|
|
fi
|
|
}
|
|
|
|
if [ -z "$1" ] || ! [ -s "$1" ]; then
|
|
printf "empty file"
|
|
read -r _
|
|
exit 1
|
|
fi
|
|
|
|
if uname | grep -q "Darwin"; then
|
|
if [ -f "$1" ]; then
|
|
open "$1" >/dev/null 2>&1 &
|
|
fi
|
|
elif command -v imvr >/dev/null 2>&1; then
|
|
if [ -f "$1" ]; then
|
|
view_dir imvr "$1" >/dev/null 2>&1 &
|
|
elif [ -d "$1" ] || [ -h "$1" ]; then
|
|
imvr "$1" >/dev/null 2>&1 &
|
|
fi
|
|
elif command -v sxiv >/dev/null 2>&1; then
|
|
if [ -f "$1" ]; then
|
|
view_dir sxiv "$1" >/dev/null 2>&1 &
|
|
elif [ -d "$1" ] || [ -h "$1" ]; then
|
|
sxiv -qt "$1" >/dev/null 2>&1 &
|
|
fi
|
|
elif command -v viu >/dev/null 2>&1; then
|
|
viu -n "$1" | less -R
|
|
else
|
|
printf "install imv/sxiv/viu"
|
|
read -r _
|
|
exit 2
|
|
fi
|