]> Sergey Matveev's repositories - nnn.git/commitdiff
imgview: handle arguments as strings (#1509)
authornblock <nblock@users.noreply.github.com>
Fri, 21 Oct 2022 12:16:06 +0000 (14:16 +0200)
committerGitHub <noreply@github.com>
Fri, 21 Oct 2022 12:16:06 +0000 (14:16 +0200)
* imgview: handle arguments as strings

Avoids the following synax errors:
line 34: [: : integer expression expected
line 49: [: : integer expression expected

* imgview: use meaningful strings as arguments

Co-authored-by: Florian Preinstorfer <florian@nblock.org>
Co-authored-by: Luuk van Baal <luukvbaal@gmail.com>
plugins/imgview

index 9f2d97909f132d469e4905eed61b65b2e4e6ffce..d8cc247a523594110acdacea7618a025dd92a4cc 100755 (executable)
@@ -31,8 +31,8 @@ exit_prompt() {
 
 make_thumbs() {
     mkdir -p "$NNN_PREVIEWDIR$dir" || return
-    if [ "$1" -eq 3 ]; then
-        [ -d "$target" ] && exit_prompt "$2 can only display a single image"
+    if [ "$1" = "viu" ] || [ "$1" = "catimg" ]; then
+        [ -d "$target" ] && exit_prompt "$1 can only display a single image"
         mime="$(file -bL --mime-type -- "$target")"
         case "$mime" in
           audio/*) ffmpeg -i "$target" "$NNN_PREVIEWDIR$target.jpg" -y >/dev/null 2>&1
@@ -45,8 +45,10 @@ make_thumbs() {
     for file in "$dir"/*; do
         if [ ! -f "$NNN_PREVIEWDIR$file.jpg" ]; then
             case "$(file -bL --mime-type -- "$file")" in
-                audio/*) [ "$1" -ne 0 ] && ffmpeg -i "$file" "$NNN_PREVIEWDIR$file.jpg" -y >/dev/null 2>&1 ;;
-                video/*) [ "$1" -ne 1 ] && ffmpegthumbnailer -i "$file" -o "$NNN_PREVIEWDIR$file.jpg" 2> /dev/null ;;
+                audio/*) [ "$1" != "sxiv" ] &&
+                    ffmpeg -i "$file" "$NNN_PREVIEWDIR$file.jpg" -y >/dev/null 2>&1 ;;
+                video/*) [ "$1" != "ucollage" ] &&
+                    ffmpegthumbnailer -i "$file" -o "$NNN_PREVIEWDIR$file.jpg" 2> /dev/null ;;
             esac
         fi
     done
@@ -77,33 +79,33 @@ elif type lsix >/dev/null 2>&1; then
     if [ -d "$target" ]; then
         cd "$target" || exit_prompt
     fi
-    make_thumbs ""
+    make_thumbs lsix
     clear
     lsix
     cd "$NNN_PREVIEWDIR$dir" && lsix
     exit_prompt
 elif type ucollage >/dev/null 2>&1; then
-    type ffmpeg >/dev/null 2>&1 && make_thumbs 1
+    type ffmpeg >/dev/null 2>&1 && make_thumbs ucollage
     UCOLLAGE_EXPAND_DIRS=1 ucollage "$dir" "$NNN_PREVIEWDIR$dir" || exit_prompt
 elif type sxiv >/dev/null 2>&1; then
-    type ffmpegthumbnailer >/dev/null 2>&1 && make_thumbs 0
+    type ffmpegthumbnailer >/dev/null 2>&1 && make_thumbs sxiv
     view_files sxiv >/dev/null 2>&1 &
 elif type nsxiv >/dev/null 2>&1; then
-    type ffmpegthumbnailer >/dev/null 2>&1 && make_thumbs 0
+    type ffmpegthumbnailer >/dev/null 2>&1 && make_thumbs sxiv
     view_files nsxiv >/dev/null 2>&1 &
 elif type imv >/dev/null 2>&1; then
-    make_thumbs ""
+    make_thumbs imv
     view_files imv >/dev/null 2>&1 &
 elif type imvr >/dev/null 2>&1; then
-    make_thumbs ""
+    make_thumbs imv
     view_files imvr >/dev/null 2>&1 &
 elif type viu >/dev/null 2>&1; then
     clear
-    make_thumbs viu
+    make_thumbs viu
     viu -n "$ret"
     exit_prompt
 elif type catimg >/dev/null 2>&1; then
-    make_thumbs catimg
+    make_thumbs catimg
     catimg "$ret"
     exit_prompt
 else