voidrice/.scripts/compiler

37 lines
1.1 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
# 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
# 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
oridir=$(pwd)
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-09-04 14:21:13 -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-07-25 12:14:38 -04:00
grep -i addbibresource "$file" &&
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
2018-07-25 13:45:05 -04:00
case "$file" in
*\.rmd) echo "require(rmarkdown); render('$file')" | R --vanilla ;;
*\.tex) textype "$file" ;;
*\.md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;;
*config.h) make && sudo make install ;;
2018-07-25 12:14:38 -04:00
*) sent "$file" 2>/dev/null & ;;
2018-04-10 17:48:45 -07:00
esac
2018-09-04 14:21:13 -04:00
cd "$oridir" || exit