Browse Source

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

master
lvgx GitHub 4 years ago
parent
commit
135821aa52
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 21 deletions
  1. +22
    -21
      plugins/preview-tui

+ 22
- 21
plugins/preview-tui 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
tmpfifopath="${TMPDIR:-/tmp}/nnn-preview-tui-fifo.$$"
mkfifo "$tmpfifopath" || return

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


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

cd "$1" || return


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


if [ -d "$1" ]; then $PAGER < "$tmpfifopath" &
# 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 &


) (
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 if [ "$PREVIEW_MODE" ] ; then


||||||
x
 
000:0
Loading…
Cancel
Save