Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.1 KiB

  1. #!/bin/sh
  2. # This script will compile or run another finishing operation on a document. I
  3. # have this script run via vim.
  4. #
  5. # Compiles .tex. groff (.mom, .ms), .rmd, .md, .org. Opens .sent files as sent
  6. # presentations. Runs scripts based on extention or shebang.
  7. #
  8. # Note that .tex files which you wish to compile with XeLaTeX should have the
  9. # string "xelatex" somewhere in a comment/command in the first 5 lines.
  10. file=$(readlink -f "$1")
  11. dir=${file%/*}
  12. base="${file%.*}"
  13. ext="${file##*.}"
  14. cd "$dir" || exit 1
  15. textype() { \
  16. command="pdflatex"
  17. ( head -n5 "$file" | grep -qi 'xelatex' ) && command="xelatex"
  18. $command --output-directory="$dir" "$base" &&
  19. grep -qi addbibresource "$file" &&
  20. biber --input-directory "$dir" "$base" &&
  21. $command --output-directory="$dir" "$base" &&
  22. $command --output-directory="$dir" "$base"
  23. }
  24. case "$ext" in
  25. # Try to keep these cases in alphabetical order.
  26. [0-9]) preconv "$file" | refer -PS -e | groff -mandoc -T pdf > "$base".pdf ;;
  27. c) cc "$file" -o "$base" && "$base" ;;
  28. cpp) g++ "$file" -o "$base" && "$base" ;;
  29. cs) mcs "$file" && mono "$base".exe ;;
  30. go) go run "$file" ;;
  31. h) sudo make install ;;
  32. java) javac -d classes "$file" && java -cp classes "${1%.*}" ;;
  33. m) octave "$file" ;;
  34. md) if [ -x "$(command -v lowdown)" ]; then
  35. lowdown -d nointem -e super "$file" -Tms | groff -mpdfmark -ms -kept > "$base".pdf
  36. elif [ -x "$(command -v groffdown)" ]; then
  37. groffdown -i "$file" | groff > "$base.pdf"
  38. else
  39. pandoc -t ms --highlight-style=kate -s -o "$base".pdf "$file"
  40. fi ; ;;
  41. mom) preconv "$file" | refer -PS -e | groff -mom -kept -T pdf > "$base".pdf ;;
  42. ms) preconv "$file" | refer -PS -e | groff -me -ms -kept -T pdf > "$base".pdf ;;
  43. org) emacs "$file" --batch -u "$USER" -f org-latex-export-to-pdf ;;
  44. py) python "$file" ;;
  45. [rR]md) Rscript -e "rmarkdown::render('$file', quiet=TRUE)" ;;
  46. s) gcc -no-pie -g -o "$base" "$file" && $base ;;
  47. rs) cargo build ;;
  48. sass) sassc -a "$file" "$base.css" ;;
  49. scad) openscad -o "$base".stl "$file" ;;
  50. sent) setsid -f sent "$file" 2>/dev/null ;;
  51. tex) textype "$file" ;;
  52. *) head -n1 "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;;
  53. esac