dotfiles

config files and scripts
git clone git://git.hanetzok.net/dotfiles
Log | Files | Refs

compiler (2262B)


      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 # Note that .tex files which you wish to compile with XeLaTeX should have the
     10 # string "xelatex" somewhere in a comment/command in the first 5 lines.
     11 
     12 file="${1}"
     13 ext="${file##*.}"
     14 dir=${file%/*}
     15 base="${file%.*}"
     16 
     17 cd "${dir}" || exit "1"
     18 
     19 case "${ext}" in
     20     [0-9]) preconv "${file}" | refer -PS -e | groff -mandoc -T pdf > "${base}.pdf" ;;
     21     mom|ms) preconv "${file}" | refer -PS -e | groff -T pdf -m"${ext}" > "${base}.pdf" ;;
     22     c) cc "${file}" -o "${base}" && "./${base}" ;;
     23     cpp) g++ "${file}" -o "${base}" && "./${base}" ;;
     24     cs) mcs "${file}" && mono "${base}.exe" ;;
     25     go) go run "${file}" ;;
     26     h) sudo make install ;;
     27     java) javac -d classes "${file}" && java -cp classes "${base}" ;;
     28     m) octave "${file}" ;;
     29     md) [ -x "$(command -v lowdown)" ] && \
     30 	    lowdown --parse-no-intraemph "${file}" -Tms | groff -mpdfmark -ms -kept -T pdf > "${base}.pdf" || \
     31 	    [ -x "$(command -v groffdown)" ] && \
     32 	    groffdown -i "${file}" | groff -T pdf > "${base}.pdf" || \
     33 	    pandoc -t ms --highlight-style="kate" -s -o "${base}.pdf" "${file}" ;;
     34     org) emacs "${file}" --batch -u "${USER}" -f org-latex-export-to-pdf ;;
     35     py) python "${file}" ;;
     36     [rR]md) Rscript -e "rmarkdown::render('${file}', quiet=TRUE)" ;;
     37     rs) cargo build ;;
     38     sass) sassc -a "${file}" "${base}.css" ;;
     39     scad) openscad -o "${base}.stl" "${file}" ;;
     40     sent) setsid -f sent "${file}" 2> "/dev/null" ;;
     41     tex)
     42 	    textarget="$(getcomproot "${file}" || echo "${file}")"
     43 	    command="pdflatex"
     44 	    head -n5 "${textarget}" | grep -qi "xelatex" && command="xelatex"
     45 	    ${command} --output-directory="${textarget%/*}" "${textarget%.*}" &&
     46 	    grep -qi addbibresource "${textarget}" &&
     47 	    biber --input-directory "${textarget%/*}" "${textarget%.*}" &&
     48 	    ${command} --output-directory="${textarget%/*}" "${textarget%.*}" &&
     49 	    ${command} --output-directory="${textarget%/*}" "${textarget%.*}"
     50 	    ;;
     51     *) sed -n '/^#!/s/^#!//p; q' "${file}" | xargs -r -I % "${file}" ;;
     52 esac