mirror of
https://github.com/jarun/nnn.git
synced 2024-12-02 19:36:51 +00:00
preview-tui: async version using $PAGER to scroll preview (#597)
This commit is contained in:
parent
b6762e292c
commit
bbcd89c8d6
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
# Note: This plugin needs a "NNN_FIFO" to work.
|
# Note: This plugin needs a "NNN_FIFO" to work.
|
||||||
#
|
#
|
||||||
# Dependencies: tmux (>=3.0) or xterm (or set $TERMINAL), file, tree
|
# Dependencies: tmux (>=3.0) or xterm or $TERMINAL, less or $PAGER, file, tree
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# You need to set a NNN_FIFO path and set a key for the plugin,
|
# You need to set a NNN_FIFO path and set a key for the plugin,
|
||||||
|
@ -22,24 +22,38 @@
|
||||||
# Authors: Todd Yamakawa, Léo Villeveygoux
|
# Authors: Todd Yamakawa, Léo Villeveygoux
|
||||||
|
|
||||||
TERMINAL="${TERMINAL:-xterm}"
|
TERMINAL="${TERMINAL:-xterm}"
|
||||||
|
PAGER="${PAGER:-less}"
|
||||||
|
|
||||||
preview_file () {
|
preview_file () {
|
||||||
|
kill %- %+ 2>/dev/null
|
||||||
clear
|
clear
|
||||||
lines=$(($(tput lines)-1))
|
|
||||||
cols=$(tput cols)
|
# 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" &
|
||||||
|
|
||||||
|
(
|
||||||
|
exec > "$tmpfifopath"
|
||||||
|
|
||||||
if [ -d "$1" ]; then
|
if [ -d "$1" ]; then
|
||||||
# Print directory tree
|
# Print directory tree
|
||||||
cd "$1" && tree | head -n $lines | cut -c 1-"$cols"
|
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: print file head
|
# Text file:
|
||||||
head -n $lines "$1" | cut -c 1-"$cols"
|
cat "$1"
|
||||||
fi
|
fi &
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
rm "$tmpfifopath"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$PREVIEW_MODE" ] ; then
|
if [ "$PREVIEW_MODE" ] ; then
|
||||||
|
|
Loading…
Reference in a new issue