texclean 966 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. usage () {
  3. cat <<EOF>&2
  4. Usage: ${0##*/} FILES.tex|FILES.texi
  5. Clean TeX/LaTeX/Texinfo projects of temp files.
  6. Argument must have a '.tex' or '.texi' extension so that we do not acccidentally
  7. remove files matching these extensions if they are not related to a TeX file.
  8. EOF
  9. }
  10. [ $# -eq 0 ] && usage && exit 1
  11. [ "$1" = "-h" ] && usage && exit
  12. [ "$1" = "--" ] && shift
  13. for i ; do
  14. case "$i" in
  15. */*) ;;
  16. *)
  17. i="./$i" ;;
  18. esac
  19. dirname="${i%/*}"
  20. basename="${i##*/}"
  21. ext=$(echo "${basename##*.}" | awk '{print tolower($0)}')
  22. basename="${basename%.*}"
  23. [ "$ext" != "tex" ] && [ "$ext" != "texi" ] && continue
  24. ## Reset arg list (big performance boost).
  25. set --
  26. for j in aux bbl blg cp cps fn glg glo gls idx ilg ind ky lof log maf mt mtc nav out pg snm synctex.gz synctex tns toc tp vr vrs xdy
  27. do
  28. set -- "$@" "$dirname/$basename.$j"
  29. done
  30. ## Do the file check last to minimize race conditions.
  31. [ -f "$i" ] || continue
  32. rm -v "$@" 2>/dev/null
  33. done