dotfiles/terminal/.config/vifm/scripts/vifm-default-viewer
Marty Oehme 7ccd7e4757
vifm: Fancy markdown display with glow or bat
For anything markdown or that gets displayed as markdown
(e.g. docx files) in the vifm preview, we now use glow
or bat to display a nicely styled and colored version.

For glow I added a script which tries to detect the
current terminal background between dark/light to
correctly set the color scheme.
2023-10-03 13:01:29 +02:00

26 lines
639 B
Bash
Executable file

#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "Usage: $0 filename"
exit 1
fi
# upper limit of lines to display for text files
nlines=250
# upper limit of bytes to display for binary files
nbytes=2048
# language of text files
language=russian
# output encoding for text files
encoding=utf-8
info=$(head -$nlines "$1" | file --mime -)
charset=${info#*=}
# shellcheck disable=2268
if [ "x$charset" == "xbinary" ]; then
hexdump -e '"%08_ax: "' -e '8/1 "%02x " " " 8/1 "%02x "' -e '" |" 16/1 "%_p"' -e '"\n"' -v -n $nbytes "$1"
else
head -$nlines "$1" | enconv -g -L $language -x $encoding | bat --color=always --style=plain
fi