mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Keep preview-tui generic
This commit is contained in:
parent
0ebc6db163
commit
5dbb511ede
|
@ -40,8 +40,11 @@ preview_file () {
|
||||||
clear
|
clear
|
||||||
|
|
||||||
encoding="$(file -b --mime-encoding "$1")"
|
encoding="$(file -b --mime-encoding "$1")"
|
||||||
|
|
||||||
|
# Detect mime type
|
||||||
mimetype="$(file --dereference --brief --mime-type -- "$1")"
|
mimetype="$(file --dereference --brief --mime-type -- "$1")"
|
||||||
|
|
||||||
|
# Detect file extention
|
||||||
ext="${1##*.}"
|
ext="${1##*.}"
|
||||||
if ! [ -z "$ext" ]; then
|
if ! [ -z "$ext" ]; then
|
||||||
ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
|
ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
|
||||||
|
@ -52,7 +55,7 @@ preview_file () {
|
||||||
|
|
||||||
cd "$1" || return
|
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.$$"
|
tmpfifopath="${TMPDIR:-/tmp}/nnn-preview-tui-fifo.$$"
|
||||||
mkfifo "$tmpfifopath" || return
|
mkfifo "$tmpfifopath" || return
|
||||||
|
|
||||||
|
@ -64,15 +67,20 @@ preview_file () {
|
||||||
)
|
)
|
||||||
|
|
||||||
rm "$tmpfifopath"
|
rm "$tmpfifopath"
|
||||||
elif beginswith "$mimetype" "image/" ; then
|
#elif beginswith "$mimetype" "image/" ; then
|
||||||
viu "$1" | head -n "$lines"
|
# viu "$1" | head -n "$lines"
|
||||||
elif beginswith "$mimetype" "text/troff" ; then
|
#elif beginswith "$mimetype" "text/troff" ; then
|
||||||
man -l "$1" &
|
# 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
|
elif [ "$encoding" = "binary" ] ; then
|
||||||
# Binary file: just print filetype info
|
# Binary file: just print filetype info
|
||||||
echo "-------- binary file --------"
|
echo "-------- binary file --------"
|
||||||
file -b "$1"
|
file -b "$1"
|
||||||
echo "-------- stat --------"
|
echo ''
|
||||||
stat "$1"
|
stat "$1"
|
||||||
else
|
else
|
||||||
# Text file:
|
# Text file:
|
||||||
|
|
Loading…
Reference in a new issue