dotfiles/terminal/.config/vifm/scripts/vifm-default-viewer

26 lines
639 B
Text
Raw Normal View History

#!/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