From 2f9c700537857591a7bad7d449f611d2caa3af4a Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Sun, 30 May 2021 20:11:54 +0200 Subject: [PATCH] Merge image plugins --- README.md | 2 +- plugins/README.md | 4 +- plugins/imgthumb | 19 ------- plugins/imgview | 127 ++++++++++++++++++++++++++++------------------ plugins/vidthumb | 27 ---------- 5 files changed, 80 insertions(+), 99 deletions(-) delete mode 100755 plugins/imgthumb delete mode 100755 plugins/vidthumb diff --git a/README.md b/README.md index 2d96c2cc..ba28ce12 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ It runs smoothly on the Pi, [Termux](https://www.youtube.com/embed/AbaauM7gUJw) - Open with desktop opener or specify a custom opener - File-specific colors (or minimal _dirs in context color_) - Icons (customize and compile-in) - - Plugins for image and video thumbnails + - Plugin for image, video and audio thumbnails - Create, list, extract, mount (FUSE based) archives - Option to open all text files in `$EDITOR` - Information diff --git a/plugins/README.md b/plugins/README.md index e8aced3b..eff34152 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -35,9 +35,8 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina | [gutenread](gutenread) | Browse, download, read from Project Gutenberg | sh | curl, unzip, w3m
[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)/
[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 | @@ -70,7 +69,6 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina | [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),
[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 | diff --git a/plugins/imgthumb b/plugins/imgthumb deleted file mode 100755 index a47f661b..00000000 --- a/plugins/imgthumb +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env sh - -# Description: View thumbnail of an image or a directory of images with lsix -# -# Dependencies: lsix -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -if [ -n "$1" ]; then - if [ -d "$1" ]; then - lsix "$1"/* - else - lsix "$1" - fi - - printf "Press any key to exit..." - read -r _ -fi diff --git a/plugins/imgview b/plugins/imgview index 667bcca7..1e378dc8 100755 --- a/plugins/imgview +++ b/plugins/imgview @@ -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")" + +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 } -listimages() { - find -L "$(dirname "$target")" -maxdepth 1 -type f -iregex \ - '.*\(jpe?g\|bmp\|webp\|ico\|svg\|png\|gif\)$' -print0 | sort -z +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 & +} + +make_thumbs() { + if [ -d "$target" ]; then cd "$target" || exit_prompt; fi + if mkdir .nthumbs >/dev/null; then + thumbs=1 + else + 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 } view_dir() { - target="$(abspath "$2")" - count="$(listimages | grep -a -m 1 -ZznF "$target" | cut -d: -f1)" - - if [ -n "$count" ]; then - if [ "$1" = 'sxiv' ]; then - listimages | xargs -0 "$1" -an "$count" -- - else - listimages | xargs -0 "$1" -n "$count" -- - fi - else - shift - "$1" -- "$@" # fallback - fi + find . -maxdepth 0 -print0 | xargs -0 "$1" -- } -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 -# `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 & diff --git a/plugins/vidthumb b/plugins/vidthumb deleted file mode 100755 index 590cf81a..00000000 --- a/plugins/vidthumb +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env sh - -# Description: Generate video thumbnails and view them -# -# Dependencies: -# - ffmpegthumbnailer: https://github.com/dirkvdb/ffmpegthumbnailer -# - lsix: https://github.com/hackerb9/lsix -# -# Shell: POSIX compliant -# Author: Arun Prakash Jana - -mkdir .nthumbs > /dev/null 2>&1 - -for file in *; do - if [ -f "$file" ]; then - ffmpegthumbnailer -i "$file" -o .nthumbs/"${file%%.*}".jpg 2> /dev/null - fi -done - -# render thumbnails in lsix -lsix .nthumbs/* - -# remove the thumbnails -rm -rf .nthumbs - -printf "Press any key to exit..." -read -r _