Skip to content

Commit

Permalink
preview-tui: directly call $PAGER on text files (jarun#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
leovilok authored May 27, 2020
1 parent bbcd89c commit 135821a
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions plugins/preview-tui
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,36 @@ TERMINAL="${TERMINAL:-xterm}"
PAGER="${PAGER:-less}"

preview_file () {
kill %- %+ 2>/dev/null
kill "$(jobs -p)" 2>/dev/null
clear

# prevent shell pipe reuse
tmpfifopath="${TMPDIR:-/tmp}/nnn-preview-tui-fifo.$$"
mkfifo "$tmpfifopath" || return

encoding="$(file -b --mime-encoding "$1")"

$PAGER < "$tmpfifopath" &
if [ -d "$1" ]; then
# Print directory tree

cd "$1" || return

(
exec > "$tmpfifopath"
# we use a FIFO to access less PID
tmpfifopath="${TMPDIR:-/tmp}/nnn-preview-tui-fifo.$$"
mkfifo "$tmpfifopath" || return

if [ -d "$1" ]; then
# Print directory tree
cd "$1" && tree
elif [ "$encoding" = "binary" ] ; then
# Binary file: just print filetype info
echo "-------- Binary file --------"
file -b "$1"
else
# Text file:
cat "$1"
fi &
$PAGER < "$tmpfifopath" &

)
(
exec > "$tmpfifopath"
tree&
)

rm "$tmpfifopath"
rm "$tmpfifopath"
elif [ "$encoding" = "binary" ] ; then
# Binary file: just print filetype info
echo "-------- Binary file --------"
file -b "$1"
else
# Text file:
$PAGER "$1" &
fi
}

if [ "$PREVIEW_MODE" ] ; then
Expand Down

0 comments on commit 135821a

Please sign in to comment.