| [gutenread](gutenread) | Browse, download, read from Project Gutenberg | sh | curl, unzip, w3m<br>[epr](https://github.com/wustho/epr) (optional) |
| [hexview](hexview) | View a file in hex in `$PAGER` | sh | [hx](https://github.com/krpors/hx)/xxd |
| [imgresize](imgresize) | Resize images in dir to screen resolution | sh | [imgp](https://github.com/jarun/imgp) |
-| [imgthumb](imgthumb) | View thumbnail of an image or dir of images | sh | [lsix](https://github.com/hackerb9/lsix) |
| [imgur](imgur) | Upload an image to imgur (from [imgur-screenshot](https://github.com/jomo/imgur-screenshot)) | bash | - |
-| [imgview](imgview) | Browse images, set wallpaper, copy path ([config](https://wiki.archlinux.org/index.php/Sxiv#Assigning_keyboard_shortcuts)), [rename](https://github.com/jarun/nnn/wiki/Basic-use-cases#browse-rename-images)| sh | [imv](https://github.com/eXeC64/imv)/[sxiv](https://github.com/muennich/sxiv)/[viu](https://github.com/atanunq/viu), less|
+| [imgview](imgview) | View (thumbnail)images, set wallpaper, [rename](https://github.com/jarun/nnn/wiki/Basic-use-cases#browse-rename-images) and [more](https://wiki.archlinux.org/index.php/Sxiv#Assigning_keyboard_shortcuts)| sh | [imv](https://github.com/eXeC64/imv)/[sxiv](https://github.com/muennich/sxiv)/[viu](https://github.com/atanunq/viu)/<br>[catimg](https://github.com/posva/catimg)/[lsix](https://github.com/hackerb9/lsix)|
| [ipinfo](ipinfo) | Fetch external IP address and whois information | sh | curl, whois |
| [kdeconnect](kdeconnect) | Send selected files to an Android device [✓] | sh | kdeconnect-cli |
| [launch](launch) | GUI application launcher | sh | fzf |
| [umounttree](umounttree) | Unmount a remote mountpoint from within | sh | fusermount |
| [upgrade](upgrade) | Upgrade nnn manually on Debian 9 Stretch | sh | curl |
| [upload](upload) | Upload to Firefox Send or ix.io (text) or file.io (bin) | sh | [ffsend](https://github.com/timvisee/ffsend), curl, jq, tr |
-| [vidthumb](vidthumb) | Show video thumbnails in terminal | sh | [ffmpegthumbnailer](https://github.com/dirkvdb/ffmpegthumbnailer),<br>[lsix](https://github.com/hackerb9/lsix) |
| [wall](wall) | Set wallpaper or change colorscheme | sh | nitrogen/pywal |
| [x2sel](x2sel) | Copy file list from system clipboard to selection | sh | _see in-file docs_ |
| [xdgdefault](xdgdefault) | Set the default app for the hovered file type | sh | xdg-utils, fzf |
#!/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 &