]> Sergey Matveev's repositories - nnn.git/commitdiff
Keep preview-tui generic
authorArun Prakash Jana <engineerarun@gmail.com>
Tue, 2 Jun 2020 00:22:47 +0000 (05:52 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Tue, 2 Jun 2020 01:00:07 +0000 (06:30 +0530)
plugins/preview-tui

index 3e2249a03724ac5b727816ea00a5d9cd314c8789..13c5639ae3a84b3f5c523eb15d92c16d14334083 100755 (executable)
@@ -40,8 +40,11 @@ preview_file () {
     clear
 
     encoding="$(file -b --mime-encoding "$1")"
+
+    # Detect mime type
     mimetype="$(file --dereference --brief --mime-type -- "$1")"
 
+    # Detect file extention
     ext="${1##*.}"
     if ! [ -z "$ext" ]; then
         ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
@@ -52,7 +55,7 @@ preview_file () {
 
         cd "$1" || return
 
-        # we use a FIFO to access less PID
+        # We use a FIFO to access less PID
         tmpfifopath="${TMPDIR:-/tmp}/nnn-preview-tui-fifo.$$"
         mkfifo "$tmpfifopath" || return
 
@@ -64,15 +67,20 @@ preview_file () {
         )
 
         rm "$tmpfifopath"
-    elif beginswith "$mimetype" "image/" ; then
-        viu "$1" | head -n "$lines"
-    elif beginswith "$mimetype" "text/troff" ; then
-        man -l "$1" &
+    #elif beginswith "$mimetype" "image/" ; then
+    #    viu "$1" | head -n "$lines"
+    #elif beginswith "$mimetype" "text/troff" ; then
+    #    man -l "$1" &
+    elif beginswith "$mimetype" "application/zip" ; then
+        #$PAGER "$(zip -sf "$1")" &
+        $PAGER "$(unzip -l "$1")" &
+    elif [ "$ext" = "gz" ] || [ "$ext" = "bz2" ] ; then
+        $PAGER "$(tar -tvf "$1")" &
     elif [ "$encoding" = "binary" ] ; then
         # Binary file: just print filetype info
         echo "-------- binary file --------"
         file -b "$1"
-        echo "-------- stat --------"
+        echo ''
         stat "$1"
     else
         # Text file: