mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
preview-tui: directly call $PAGER on text files (#599)
This commit is contained in:
parent
bbcd89c8d6
commit
135821aa52
|
@ -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
|
||||||
exec > "$tmpfifopath"
|
|
||||||
|
|
||||||
if [ -d "$1" ]; then
|
# we use a FIFO to access less PID
|
||||||
# Print directory tree
|
tmpfifopath="${TMPDIR:-/tmp}/nnn-preview-tui-fifo.$$"
|
||||||
cd "$1" && tree
|
mkfifo "$tmpfifopath" || return
|
||||||
elif [ "$encoding" = "binary" ] ; then
|
|
||||||
# Binary file: just print filetype info
|
|
||||||
echo "-------- Binary file --------"
|
|
||||||
file -b "$1"
|
|
||||||
else
|
|
||||||
# Text file:
|
|
||||||
cat "$1"
|
|
||||||
fi &
|
|
||||||
|
|
||||||
)
|
$PAGER < "$tmpfifopath" &
|
||||||
|
|
||||||
rm "$tmpfifopath"
|
(
|
||||||
|
exec > "$tmpfifopath"
|
||||||
|
tree&
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in a new issue