ambevar-dotfiles/.scripts/asciify

81 lines
1.8 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/sh
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
cat <<EOF
Usage: ${0##*/} [FILES]
Convert non-ASCII characters to their ASCII equivalent. If files are provided,
convert them in-place. Otherwise convert standard input to standard output.
EOF
exit
fi
_asciify()
{
unset OPT
if [ $# -ge 1 ]; then
OPT=-i
fi
sed $OPT \
-e 's/[áàâä]/a/g' \
-e 's/[éèêë]/e/g' \
-e 's/[íìîï]/i/g' \
-e 's/[óòôö]/o/g' \
-e 's/[úùûü]/u/g' \
-e 's/[ýỳŷÿ]/y/g' \
-e 's/[ÁÀÂÄ]/A/g' \
-e 's/[ÉÈÊË]/E/g' \
-e 's/[ÍÌÎÏ]/I/g' \
-e 's/[ÓÒÔÖ]/O/g' \
-e 's/[ÚÙÛÜ]/U/g' \
-e 's/[ÝỲŶŸ]/Y/g' \
-e 's/[ñ]/n/g' \
-e 's/[œ]/oe/g' \
-e 's/[Œ]/Oe/g' \
-e 's/[æ]/ae/g' \
-e 's/[Æ]/Ae/g' \
-e 's/[ç]/c/g' \
-e 's/[Ç]/C/g' \
-e 's/[ß]/ss/g' \
-e 's/[«»„“”‚‘’]/"/g' \
-e 's/[©]/(C)/g' \
-e 's/[®]/(R)/g' \
-e 's/[™]/(TM)/g' \
-e 's/[¥]/Y/g' \
-e 's/[Ð]/D/g' \
-e 's/[ŀ]/l/g' \
-e 's/[Ŀ]/L/g' \
-e 's/[€]/euro/g' \
-e 's/[¢]/cent/g' \
-e 's/[£]/pound/g' \
-e 's/[µ]/mu/g' \
-e 's/[²]/^2/g' \
-e 's/[³]/^3/g' \
-e 's/[¡]/!/g' \
-e 's/[¿]/?/g' \
-e 's/[]/-/g' \
-e 's/[…]/.../g' \
-e 's/[≤]/<=/g' \
-e 's/[≥]/>=/g' \
-e 's/[±]/+\/-/g' \
-e 's/[≠]/!=/g' \
-e 's/[⋅]/./g' \
-e 's/[×]/x/g' \
-e 's/[÷]/\//g' \
-e 's/[↓]/|/g' \
-e 's/[↑]/^/g' \
-e 's/[←]/<=/g' \
-e 's/[→]/=>/g' \
"$@"
}
if [ $# -ge 1 ]; then
for i; do
_asciify "$i"
done
else
_asciify
fi