forked from jarun/nnn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,101 @@ | ||
#!/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 | ||
# Description: Open hovered or current directory in image viewer. | ||
# Thumbnails for audio and video files are generated | ||
# and deleted on exit. Supported image viewers open | ||
# in thumbnail mode when the hovered entry is a directory. | ||
# | ||
# Dependencies: | ||
# - imv (https://github.com/eXeC64/imv) or, | ||
# - sxiv (https://github.com/muennich/sxiv) or, | ||
# - viu (https://github.com/atanunq/viu), less | ||
# - viu (https://github.com/atanunq/viu), or | ||
# - catimg (https://github.com/posva/catimg), or | ||
# - lsix (https://github.com/hackerb9/lsix) | ||
# | ||
# Shell: POSIX compliant | ||
# Author: Arun Prakash Jana | ||
# Author: Arun Prakash Jana, Luuk van Baal | ||
|
||
abspath() { | ||
case "$1" in | ||
/*) printf "%s\n" "$1";; | ||
*) printf "%s\n" "$PWD/$1";; | ||
esac | ||
} | ||
target="$(readlink -f "$1")" | ||
|
||
listimages() { | ||
find -L "$(dirname "$target")" -maxdepth 1 -type f -iregex \ | ||
'.*\(jpe?g\|bmp\|webp\|ico\|svg\|png\|gif\)$' -print0 | sort -z | ||
exit_prompt() { | ||
[ -n "$1" ] && printf "%s\n" "$1" | ||
printf "%s" "Press any key to exit..." | ||
cfg=$(stty -g); stty raw -echo; head -c 1; stty "$cfg" | ||
clear | ||
exit | ||
} | ||
|
||
view_dir() { | ||
target="$(abspath "$2")" | ||
count="$(listimages | grep -a -m 1 -ZznF "$target" | cut -d: -f1)" | ||
nthumb_cleanup() { | ||
[ -n "$!" ] && while [ -e /proc/"$!" ]; do sleep 1; done | ||
if [ -f "$target" ]; then | ||
rm -r "$(dirname "$target")"/.nthumbs | ||
elif [ -d "$target" ]; then | ||
rm -r "$target"/.nthumbs | ||
fi & | ||
} | ||
|
||
if [ -n "$count" ]; then | ||
if [ "$1" = 'sxiv' ]; then | ||
listimages | xargs -0 "$1" -an "$count" -- | ||
else | ||
listimages | xargs -0 "$1" -n "$count" -- | ||
fi | ||
make_thumbs() { | ||
if [ -d "$target" ]; then cd "$target" || exit_prompt; fi | ||
if mkdir .nthumbs >/dev/null; then | ||
thumbs=1 | ||
else | ||
shift | ||
"$1" -- "$@" # fallback | ||
exit_prompt | ||
fi | ||
for file in *; do | ||
case "$(file -bL --mime-type -- "$file")" in | ||
image/*) ln -s "$PWD/$file" "$PWD/.nthumbs/$file" ;; | ||
audio/*) ffmpeg -i "$file" ".nthumbs/${file%%.*}.jpg" -y >/dev/null 2>&1;; | ||
video/*) ffmpegthumbnailer -i "$file" -o .nthumbs/"${file%%.*}".jpg 2> /dev/null ;; | ||
esac | ||
done | ||
cd .nthumbs || return | ||
} | ||
|
||
if [ -z "$1" ] || ! [ -s "$1" ]; then | ||
printf "empty file" | ||
read -r _ | ||
exit 1 | ||
fi | ||
view_dir() { | ||
find . -maxdepth 0 -print0 | xargs -0 "$1" -- | ||
} | ||
|
||
if uname | grep -q "Darwin"; then | ||
if [ -f "$1" ]; then | ||
open "$1" >/dev/null 2>&1 & | ||
fi | ||
# `imvr` is often callable as `imv` on Linux distros | ||
# You might need to change the reference below | ||
elif type 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 & | ||
[ -f "$1" ] && open "$1" >/dev/null 2>&1 & | ||
elif type lsix >/dev/null 2>&1; then | ||
if [ -d "$target" ]; then | ||
cd "$target" || exit_prompt | ||
fi | ||
make_thumbs | ||
clear | ||
lsix | ||
nthumb_cleanup | ||
exit_prompt | ||
elif type 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 -aqt "$1" >/dev/null 2>&1 & | ||
make_thumbs | ||
if [ -f "$target" ]; then | ||
view_dir sxiv >/dev/null 2>&1 & | ||
elif [ -d "$target" ]; then | ||
sxiv -aqt . >/dev/null 2>&1 & | ||
fi | ||
elif type imv >/dev/null 2>&1; then | ||
make_thumbs | ||
if [ -f "$target" ]; then | ||
view_dir imv >/dev/null 2>&1 & | ||
elif [ -d "$target" ]; then | ||
imv . >/dev/null 2>&1 & | ||
fi | ||
elif type imvr >/dev/null 2>&1; then | ||
make_thumbs | ||
if [ -f "$target" ]; then | ||
view_dir imvr >/dev/null 2>&1 & | ||
elif [ -d "$target" ]; then | ||
imvr . >/dev/null 2>&1 & | ||
fi | ||
elif type viu >/dev/null 2>&1; then | ||
viu -n "$1" | less -R | ||
clear | ||
viu -n "$1" | ||
exit_prompt | ||
elif type catimg >/dev/null 2>&1; then | ||
clear | ||
catimg "$1" | ||
exit_prompt | ||
else | ||
printf "Please install imv/sxiv/viu and check their callable names match the plugin source" | ||
read -r _ | ||
exit 2 | ||
exit_prompt "Please install sxiv/imv/viu/catimg/lsix." | ||
fi | ||
[ -n "$thumbs" ] && nthumb_cleanup & |
This file was deleted.
Oops, something went wrong.