dotfiles/terminal/.config/vifm/scripts/vifm-default-viewer
Marty Oehme 9781b26b22
terminal: Create module to consolidate term utils
Terminal application, a variety of shell configurations, terminal file
and session management all consolidated in one place.
2023-01-07 16:11:40 +01:00

26 lines
604 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
fi