diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2020-06-02 05:52:47 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2020-06-02 06:30:07 +0530 |
commit | 5dbb511ede3e02e967e97fa1ca9d1755223c46bb (patch) | |
tree | bf01d9d681703e6ea0ca4bccd181e98b2ff50578 | |
parent | 0ebc6db163ea3873fd55fc8adf4236c05060315a (diff) | |
download | nnn-5dbb511ede3e02e967e97fa1ca9d1755223c46bb.tar.gz |
Keep preview-tui generic
-rwxr-xr-x | plugins/preview-tui | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/plugins/preview-tui b/plugins/preview-tui index 3e2249a..13c5639 100755 --- a/plugins/preview-tui +++ b/plugins/preview-tui @@ -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: |