dotfiles

My dotfiles: zsh, lf, sxiv, i3, ranger, mpd and more
Log | Files | Refs | Submodules | README | LICENSE

compiler (1838B)


      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.  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
     18 
     19 textype() { \
     20 	command="pdflatex"
     21 	( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex"
     22 	$command --output-directory="$dir" "$base" &&
     23 	grep -i addbibresource "$file" >/dev/null &&
     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 	[0-9]) preconv "$file" | refer -PS -e | groff -mandoc -T pdf > "$base".pdf ;;
     31 	c) cc "$file" -o "$base" && "$base" ;;
     32 	go) go run "$file" ;;
     33 	h) sudo make install ;;
     34 	m) octave "$file" ;;
     35 	md)	if  [ -x "$(command -v lowdown)" ]; then
     36 			lowdown -d nointem -e super "$file" -Tms | groff -mpdfmark -ms -kept > "$base".pdf
     37 		elif [ -x "$(command -v groffdown)" ]; then
     38 			groffdown -i "$file" | groff > "$base.pdf"
     39 		else
     40 			pandoc "$file" --pdf-engine=xelatex -o "$base".pdf
     41 		fi ; ;;
     42 	mom) preconv "$file" | refer -PS -e | groff -mom -kept -T pdf > "$base".pdf ;;
     43 	ms) preconv "$file" | refer -PS -e | groff -me -ms -kept -T pdf > "$base".pdf ;;
     44 	py) python "$file" ;;
     45 	[rR]md) Rscript -e "rmarkdown::render('$file', quiet=TRUE)" ;;
     46 	rs) cargo build ;;
     47    sass) sassc -a "$file" "$base.css" ;;
     48 	scad) openscad -o "$base".stl "$file" ;;
     49 	sent) setsid -f sent "$file" 2>/dev/null ;;
     50 	tex) textype "$file" ;;
     51 	*) sed 1q "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;;
     52 esac