compiler (1726B)
1 #!/bin/sh 2 3 # This script will compile or run another finishing operation on a document. I 4 # have this script run via vim. 5 6 # Compiles .tex. groff (.mom, .ms), .rmd, .md, .org. Opens .sent files as sent 7 # presentations. Runs scripts based on extension or shebang. 8 9 file="${1}" 10 ext="${file##*.}" 11 dir=${file%/*} 12 base="${file%.*}" 13 14 cd "${dir}" || exit "1" 15 16 case "${ext}" in 17 [0-9]) preconv "${file}" | refer -PS -e | groff -mandoc -T pdf > "${base}.pdf" ;; 18 mom|ms) preconv "${file}" | refer -PS -e | groff -T pdf -m"${ext}" > "${base}.pdf" ;; 19 c) cc "${file}" -o "${base}" && "${base}" ;; 20 cob) cobc -x -o "$base" "$file" && "$base" ;; 21 cpp|cc) g++ "${file}" -o "${base}" && "${base}" ;; 22 cs) mcs "${file}" && mono "${base}.exe" ;; 23 go) go run "${file}" ;; 24 h) doas make install ;; 25 java) javac -d classes "${file}" && java -cp classes "${base}" ;; 26 m) octave "${file}" ;; 27 md) [ -x "$(command -v lowdown)" ] && \ 28 lowdown --parse-no-intraemph "${file}" -Tms | groff -mpdfmark -ms -kept -T pdf > "${base}.pdf" || \ 29 [ -x "$(command -v groffdown)" ] && \ 30 groffdown -i "${file}" | groff -T pdf > "${base}.pdf" || \ 31 pandoc -t ms --highlight-style="kate" -s -o "${base}.pdf" "${file}" ;; 32 org) emacs "${file}" --batch -u "${USER}" -f org-latex-export-to-pdf ;; 33 py) python "${file}" ;; 34 rink) rink -f "${file}" ;; 35 [rR]md) Rscript -e "rmarkdown::render('${file}', quiet=TRUE)" ;; 36 rs) cargo build && cargo run --quiet ;; 37 sass) sassc -a "${file}" "${base}.css" ;; 38 scad) openscad -o "${base}.stl" "${file}" ;; 39 sent) setsid -f sent "${file}" 2> "/dev/null" ;; 40 tex) latexmk ;; 41 *) sed -n '/^#!/s/^#!//p; q' "${file}" | xargs -r -I % "${file}" ;; 42 esac