dots

Personal dotfiles
git clone git://git.gormless.xyz/dots.git
Log | Files | Refs

compiler (2114B)


      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 extention 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=$(readlink -f "$1")
     13 dir=${file%/*}
     14 base="${file%.*}"
     15 ext="${file##*.}"
     16 
     17 cd "$dir" || exit 1
     18 
     19 textype() { \
     20 	command="pdflatex"
     21 	( head -n5 "$file" | grep -qi 'xelatex' ) && command="xelatex"
     22 	$command --output-directory="$dir" "$base" &&
     23 	grep -qi addbibresource "$file" &&
     24 	biber --input-directory "$dir" "$base" &&
     25 	$command --output-directory="$dir" "$base" &&
     26 	$command --output-directory="$dir" "$base"
     27 }
     28 
     29 case "$ext" in
     30 	# Try to keep these cases in alphabetical order.
     31 	[0-9]) preconv "$file" | refer -PS -e | groff -mandoc -T pdf > "$base".pdf ;;
     32 	c) cc "$file" -o "$base" && "$base" ;;
     33 	cpp) g++ "$file" -o "$base" && "$base" ;;
     34 	cs) mcs "$file" && mono "$base".exe ;;
     35 	go) go run "$file" ;;
     36 	h) doas make install ;;
     37 	java) javac -d classes "$file" && java -cp classes "${1%.*}" ;;
     38 	m) octave "$file" ;;
     39 	md)	if  [ -x "$(command -v lowdown)" ]; then
     40 			lowdown -d nointem -e super "$file" -Tms | groff -mpdfmark -ms -kept > "$base".pdf
     41 		elif [ -x "$(command -v groffdown)" ]; then
     42 			groffdown -i "$file" | groff > "$base.pdf"
     43 		else
     44 			pandoc -t ms --highlight-style=kate -s -o "$base".pdf "$file"
     45 		fi ; ;;
     46 	mom) preconv "$file" | refer -PS -e | groff -mom -kept -T pdf > "$base".pdf ;;
     47 	ms) preconv "$file" | refer -PS -e | groff -me -ms -kept -T pdf > "$base".pdf ;;
     48 	org) emacs "$file" --batch -u "$USER" -f org-latex-export-to-pdf ;;
     49 	py) python "$file" ;;
     50 	[rR]md) Rscript -e "rmarkdown::render('$file', quiet=TRUE)" ;;
     51 	rs) cargo build ;;
     52 	sass) sassc -a "$file" "$base.css" ;;
     53 	scad) openscad -o "$base".stl "$file" ;;
     54 	sent) setsid -f sent "$file" 2>/dev/null ;;
     55 	tex) textype "$file" ;;
     56 	*) head -n1 "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;;
     57 esac