aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/preview-tui
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-06-01 19:22:16 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-06-01 19:22:16 +0530
commitca8bc8bf3059be0402c16032823cb061281141cd (patch)
tree07e9115020e79d85c5443f8e84f7efdc9b980297 /plugins/preview-tui
parentf6d9a6b34d695908b752737d0a2cba6733de7800 (diff)
downloadnnn-ca8bc8bf3059be0402c16032823cb061281141cd.tar.gz
Support mime, extension in preview-tui
Diffstat (limited to 'plugins/preview-tui')
-rwxr-xr-xplugins/preview-tui14
1 files changed, 14 insertions, 0 deletions
diff --git a/plugins/preview-tui b/plugins/preview-tui
index 1c8c41d..3e2249a 100755
--- a/plugins/preview-tui
+++ b/plugins/preview-tui
@@ -31,11 +31,21 @@ SPLIT=
lines=$(($(tput lines)-1))
cols=$(tput cols)
+beginswith() {
+ case $1 in "$2"*) true;; *) false;; esac;
+}
+
preview_file () {
kill "$(jobs -p)" 2>/dev/null
clear
encoding="$(file -b --mime-encoding "$1")"
+ mimetype="$(file --dereference --brief --mime-type -- "$1")"
+
+ ext="${1##*.}"
+ if ! [ -z "$ext" ]; then
+ ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
+ fi
if [ -d "$1" ]; then
# Print directory tree
@@ -54,6 +64,10 @@ preview_file () {
)
rm "$tmpfifopath"
+ elif beginswith "$mimetype" "image/" ; then
+ viu "$1" | head -n "$lines"
+ elif beginswith "$mimetype" "text/troff" ; then
+ man -l "$1" &
elif [ "$encoding" = "binary" ] ; then
# Binary file: just print filetype info
echo "-------- binary file --------"