summaryrefslogtreecommitdiff
path: root/.local/bin/compiler
blob: e6a6db3ffd872ed13f20f2e0b75b32a74a329edb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh
# This script will compile or run another finishing operation on a document. I
# have this script run via vim.
#
# Compiles .tex. groff (.mom, .ms), .rmd, .md.
# Opens .sent files as sent presentations.
# Runs scripts based on extention or shebang

file=$(readlink -f "$1")
dir=$(dirname "$file")
base="${file%.*}"

cd "$dir" || exit

textype() {
	command="pdflatex"
	(sed 5q "$file" | grep -i -q 'xelatex') && command="xelatex"
	$command --output-directory="$dir" "$base" &&
		grep -i addbibresource "$file" >/dev/null &&
		biber --input-directory "$dir" "$base" &&
		$command --output-directory="$dir" "$base" &&
		$command --output-directory="$dir" "$base"
}

case "$file" in
*\.ms) refer -PS -e -p"$REFERBIB" "$file" | groff -me -ms -kejpt -T pdf >"$base".pdf ;;
*\.gd) groffdown "$file" | refer -PS -e "-p$REFERBIB" | groff -me -ms -kejpt -T pdf >"$base".pdf ;;
# *\.gd) groffdown "$file" | refer -PS -e "$REFERBIB" | groff -me -ms -kejpt -T pdf > "$base".pdf ;;
*\.mom) refer -PS -e -p"$REFERBIB" "$file" | groff -mom -kejpt -T pdf >"$base".pdf ;;
*\.rmd) echo "require(rmarkdown); render('$file')" | R -q --vanilla ;;
*\.rnw) Rscript -e "knitr::knit2pdf('""$file""',compiler='xelatex')" ;;
*\.tex) textype "$file" ;;
*\.md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;;
*config.h) make && sudo make install ;;
*\.c) cc "$file" -o "$base" && "$base" ;;
*\.py) python "$file" ;;
*\.go) go run "$file" ;;
*\.sent) setsid sent "$file" 2>/dev/null & ;;
*.Xresources) xrdb -load "$file" ;;
*) sed 1q "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;;
esac