2019-09-30 12:49:14 +00:00
|
|
|
#!/bin/zsh
|
2021-08-31 14:53:01 +00:00
|
|
|
#dep:mdcat iconv chardetect
|
2019-09-30 12:49:14 +00:00
|
|
|
|
|
|
|
MDCAT=/usr/bin/mdcat
|
2021-08-31 14:53:01 +00:00
|
|
|
#encoding=$(file -i "$1" | sed "s/.*charset=\(.*\)$/\1/")
|
|
|
|
if [[ $2 ]]; then
|
|
|
|
encoding=$2
|
|
|
|
else
|
|
|
|
encoding=$(chardetect "$1" | grep -oP '(?<=: )\S*')
|
|
|
|
fi
|
2019-09-30 12:49:14 +00:00
|
|
|
if ! iconv -f $encoding <<<"" &> /dev/null; then
|
|
|
|
cat "$1"
|
|
|
|
elif [[ $encoding != 'utf-8' ]]; then
|
|
|
|
iconv -f $encoding -t 'utf-8' < "$1" | $MDCAT /dev/stdin
|
|
|
|
else
|
|
|
|
$MDCAT $1
|
|
|
|
fi
|