2018-09-04 18:21:13 +00:00
|
|
|
#!/bin/sh
|
2018-04-11 00:48:45 +00:00
|
|
|
|
2018-07-25 17:45:05 +00:00
|
|
|
# This script will compile or run another finishing operation on a document. I
|
2018-10-26 04:28:09 +00:00
|
|
|
# have this script run via vim.
|
2018-04-11 00:48:45 +00:00
|
|
|
#
|
2018-07-25 17:45:05 +00: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 04:28:09 +00:00
|
|
|
# c files: Compiles via whatever compiler is set to cc. Usually gcc.
|
2018-10-15 04:15:33 +00:00
|
|
|
# py files: runs via python command
|
|
|
|
# go files: compiles and runs with "go run"
|
2018-07-25 17:45:05 +00:00
|
|
|
# config.h files: (For suckless utils) recompiles and installs program.
|
|
|
|
# all others: run `sent` to show a presentation
|
2018-04-11 00:48:45 +00:00
|
|
|
|
2018-07-24 17:34:38 +00:00
|
|
|
file=$(readlink -f "$1")
|
2018-07-25 17:45:05 +00:00
|
|
|
dir=$(dirname "$file")
|
2018-04-11 00:48:45 +00:00
|
|
|
base="${file%.*}"
|
2018-10-26 04:28:09 +00:00
|
|
|
shebang=$(sed -n 1p "$file")
|
2018-10-15 04:15:33 +00:00
|
|
|
|
2018-10-26 04:28:09 +00:00
|
|
|
cd "$dir" || exit
|
2018-04-11 00:48:45 +00:00
|
|
|
|
2018-07-25 16:14:38 +00:00
|
|
|
textype() { \
|
|
|
|
command="pdflatex"
|
|
|
|
( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex"
|
2018-07-25 17:45:05 +00:00
|
|
|
$command --output-directory="$dir" "$base" &&
|
2018-10-26 04:28:09 +00:00
|
|
|
grep -i addbibresource "$file" >/dev/null &&
|
2018-07-25 17:45:05 +00:00
|
|
|
biber --input-directory "$dir" "$base" &&
|
|
|
|
$command --output-directory="$dir" "$base" &&
|
|
|
|
$command --output-directory="$dir" "$base"
|
2018-07-25 16:14:38 +00:00
|
|
|
}
|
2018-04-11 00:48:45 +00:00
|
|
|
|
2018-10-15 04:15:33 +00:00
|
|
|
shebangtest() {
|
|
|
|
case "$shebang" in
|
|
|
|
\#\!*) "$file" ;;
|
|
|
|
*) sent "$file" 2>/dev/null & ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2018-07-25 17:45:05 +00:00
|
|
|
case "$file" in
|
2018-11-04 00:59:02 +00:00
|
|
|
*\.ms) refer -PS -e "$file" | groff -me -ms -kejpt -T pdf > "$base".pdf ;;
|
|
|
|
*\.rmd) echo "require(rmarkdown); render('$file')" | R --vanilla ;;
|
2018-07-25 17:45:05 +00:00
|
|
|
*\.tex) textype "$file" ;;
|
|
|
|
*\.md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;;
|
|
|
|
*config.h) make && sudo make install ;;
|
2018-10-15 04:15:33 +00:00
|
|
|
*\.c) cc "$file" -o "$base" && "$base" ;;
|
|
|
|
*\.py) python "$file" ;;
|
|
|
|
*\.go) go run "$file" ;;
|
|
|
|
*) shebangtest ;;
|
2018-04-11 00:48:45 +00:00
|
|
|
esac
|