asciify 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/sh
  2. if [ "$1" = "-h" ]; then
  3. cat <<EOF>&2
  4. Usage: ${0##*/} [FILES]
  5. Convert non-ASCII characters to their ASCII equivalent. If no files are
  6. provided, use stdin.
  7. Options:
  8. -i: If files are provided, convert them in-place.
  9. EOF
  10. exit
  11. fi
  12. unset OPT
  13. if [ "$1" = "-i" ]; then
  14. OPT=-i
  15. shift
  16. fi
  17. ## Note that we also use 'sed -i' to edit files instead of 'ex'. Otherwise the
  18. ## code looks ugly if we try to handle both stdin and files with only one
  19. ## call. Besides, ex does not support multiple file editing.
  20. sed $OPT \
  21. -e 's/[áàâä]/a/g' \
  22. -e 's/[éèêë]/e/g' \
  23. -e 's/[íìîï]/i/g' \
  24. -e 's/[óòôö]/o/g' \
  25. -e 's/[úùûü]/u/g' \
  26. -e 's/[ýỳŷÿ]/y/g' \
  27. -e 's/[ÁÀÂÄ]/A/g' \
  28. -e 's/[ÉÈÊË]/E/g' \
  29. -e 's/[ÍÌÎÏ]/I/g' \
  30. -e 's/[ÓÒÔÖ]/O/g' \
  31. -e 's/[ÚÙÛÜ]/U/g' \
  32. -e 's/[ÝỲŶŸ]/Y/g' \
  33. -e 's/[ñ]/n/g' \
  34. -e 's/[œ]/oe/g' \
  35. -e 's/[Œ]/Oe/g' \
  36. -e 's/[æ]/ae/g' \
  37. -e 's/[Æ]/Ae/g' \
  38. -e 's/[ç]/c/g' \
  39. -e 's/[Ç]/C/g' \
  40. -e 's/[ß]/ss/g' \
  41. -e 's/[«»„“”‚‘’]/"/g' \
  42. -e 's/[©]/(C)/g' \
  43. -e 's/[®]/(R)/g' \
  44. -e 's/[™]/(TM)/g' \
  45. -e 's/[¥]/Y/g' \
  46. -e 's/[Ð]/D/g' \
  47. -e 's/[ŀ]/l/g' \
  48. -e 's/[Ŀ]/L/g' \
  49. -e 's/[€]/euro/g' \
  50. -e 's/[¢]/cent/g' \
  51. -e 's/[£]/pound/g' \
  52. -e 's/[µ]/mu/g' \
  53. -e 's/[²]/^2/g' \
  54. -e 's/[³]/^3/g' \
  55. -e 's/[¡]/!/g' \
  56. -e 's/[¿]/?/g' \
  57. -e 's/[–‑]/-/g' \
  58. -e 's/[…]/.../g' \
  59. -e 's/[≤]/<=/g' \
  60. -e 's/[≥]/>=/g' \
  61. -e 's/[±]/+\/-/g' \
  62. -e 's/[≠]/!=/g' \
  63. -e 's/[⋅]/./g' \
  64. -e 's/[×]/x/g' \
  65. -e 's/[÷]/\//g' \
  66. -e 's/[↓]/|/g' \
  67. -e 's/[↑]/^/g' \
  68. -e 's/[←]/<=/g' \
  69. -e 's/[→]/=>/g' \
  70. "$@"