mirror of
https://github.com/jarun/nnn.git
synced 2024-11-17 08:32:36 +00:00
preview-kitty polish (async version + text render for SVGs) (#591)
* preview-kitty: async version The plugin now aborts slow file viewers. * preview-kitty: use text mode preview for SVG
This commit is contained in:
parent
adf381acee
commit
c7af686b4e
|
@ -27,6 +27,7 @@
|
||||||
# Authors: Léo Villeveygoux
|
# Authors: Léo Villeveygoux
|
||||||
|
|
||||||
preview_file () {
|
preview_file () {
|
||||||
|
kill %% 2>/dev/null
|
||||||
clear
|
clear
|
||||||
lines=$(($(tput lines)-1))
|
lines=$(($(tput lines)-1))
|
||||||
cols=$(tput cols)
|
cols=$(tput cols)
|
||||||
|
@ -37,18 +38,20 @@ preview_file () {
|
||||||
# Print directory tree
|
# Print directory tree
|
||||||
# shellcheck disable=SC2015
|
# shellcheck disable=SC2015
|
||||||
cd "$1" && \
|
cd "$1" && \
|
||||||
COLUMNS=$cols exa -G --colour=always 2>/dev/null || ls --color=alway
|
(COLUMNS=$cols exa -G --colour=always 2>/dev/null ||\
|
||||||
elif [ "${mime%%/*}" = "image" ] ; then
|
ls --color=alway) | head -n $lines &
|
||||||
kitty +kitten icat --silent --transfer-mode=stream --stdin=no "$1"
|
# remove second clause to preview SVG files (but this is slow)
|
||||||
|
elif [ "${mime%%/*}" = "image" ] && [ "$encoding" = "binary" ] ; then
|
||||||
|
kitty +kitten icat --silent --transfer-mode=stream --stdin=no "$1" &
|
||||||
elif [ "$encoding" = "binary" ] ; then
|
elif [ "$encoding" = "binary" ] ; then
|
||||||
# Binary file: show file info
|
# Binary file: show file info
|
||||||
printf -- "-------- \033[1;31mBinary file\033[0m --------\n"
|
printf -- "-------- \033[1;31mBinary file\033[0m --------\n"
|
||||||
mediainfo "$1" 2>/dev/null || file -b "$1"
|
(mediainfo "$1" 2>/dev/null || file -b "$1") | head -n $((lines - 1)) &
|
||||||
else
|
else
|
||||||
# Text file: print colored file content
|
# Text file: print colored file content
|
||||||
bat --terminal-width="$cols" --paging=never --decorations=always \
|
(bat --terminal-width="$cols" --paging=never --decorations=always \
|
||||||
--color=always "$1" 2>/dev/null || cat
|
--color=always "$1" 2>/dev/null || cat) | head -n $lines &
|
||||||
fi | head -n $lines
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$PREVIEW_MODE" ] ; then
|
if [ "$PREVIEW_MODE" ] ; then
|
||||||
|
|
Loading…
Reference in a new issue