preview-tui: directly call $PAGER on text files (#599)

This commit is contained in:
lvgx 2020-05-28 01:34:53 +02:00 committed by GitHub
parent bbcd89c8d6
commit 135821aa52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,35 +25,36 @@ TERMINAL="${TERMINAL:-xterm}"
PAGER="${PAGER:-less}" PAGER="${PAGER:-less}"
preview_file () { preview_file () {
kill %- %+ 2>/dev/null kill "$(jobs -p)" 2>/dev/null
clear clear
# prevent shell pipe reuse encoding="$(file -b --mime-encoding "$1")"
if [ -d "$1" ]; then
# Print directory tree
cd "$1" || return
# 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
encoding="$(file -b --mime-encoding "$1")"
$PAGER < "$tmpfifopath" & $PAGER < "$tmpfifopath" &
( (
exec > "$tmpfifopath" exec > "$tmpfifopath"
tree&
)
if [ -d "$1" ]; then rm "$tmpfifopath"
# Print directory tree
cd "$1" && tree
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"
else else
# Text file: # Text file:
cat "$1" $PAGER "$1" &
fi & fi
)
rm "$tmpfifopath"
} }
if [ "$PREVIEW_MODE" ] ; then if [ "$PREVIEW_MODE" ] ; then