voidrice/.scripts/compiler

53 lines
1.6 KiB
Text
Raw Normal View History

2018-09-04 14:21:13 -04:00
#!/bin/sh
2018-04-10 17:48:45 -07:00
2018-07-25 13:45:05 -04:00
# This script will compile or run another finishing operation on a document. I
2018-10-26 00:28:09 -04:00
# have this script run via vim.
2018-04-10 17:48:45 -07:00
#
2018-07-25 13:45:05 -04:00
# tex files: Compiles to pdf, including bibliography if necessary
# md files: Compiles to pdf via pandoc
# rmd files: Compiles via R Markdown
2018-10-26 00:28:09 -04:00
# c files: Compiles via whatever compiler is set to cc. Usually gcc.
# py files: runs via python command
# go files: compiles and runs with "go run"
2018-07-25 13:45:05 -04:00
# config.h files: (For suckless utils) recompiles and installs program.
# all others: run `sent` to show a presentation
2018-04-10 17:48:45 -07:00
2018-07-24 13:34:38 -04:00
file=$(readlink -f "$1")
2018-07-25 13:45:05 -04:00
dir=$(dirname "$file")
2018-04-10 17:48:45 -07:00
base="${file%.*}"
2018-10-26 00:28:09 -04:00
shebang=$(sed -n 1p "$file")
2018-10-26 00:28:09 -04:00
cd "$dir" || exit
2018-04-10 17:48:45 -07:00
2018-07-25 12:14:38 -04:00
textype() { \
command="pdflatex"
( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex"
2018-07-25 13:45:05 -04:00
$command --output-directory="$dir" "$base" &&
2018-10-26 00:28:09 -04:00
grep -i addbibresource "$file" >/dev/null &&
2018-07-25 13:45:05 -04:00
biber --input-directory "$dir" "$base" &&
$command --output-directory="$dir" "$base" &&
$command --output-directory="$dir" "$base"
2018-07-25 12:14:38 -04:00
}
2018-04-10 17:48:45 -07:00
shebangtest() {
case "$shebang" in
\#\!*) "$file" ;;
*) sent "$file" 2>/dev/null & ;;
esac
}
2018-10-26 00:28:30 -04:00
# If there is a global $REFBIB variable/file for `refer`, use it.
[ -f "$REFBIB" ] && groffbib="-p $REFBIB"
2018-07-25 13:45:05 -04:00
case "$file" in
2018-10-30 17:47:42 -04:00
*\.ms) refer -PS -e $groffbib "$file" | groff -kejpt -ms -T pdf > "$base".pdf ;;
*\.rmd) echo "require(rmarkdown); render('$file')" | R --vanilla && mv "$base".pdf "$dir"/pdfs;;
2018-07-25 13:45:05 -04:00
*\.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" ;;
*) shebangtest ;;
2018-04-10 17:48:45 -07:00
esac