voidrice/.scripts/compiler
Matthew Graham 870af2c793 Run programs without extensions
This change gives the ability to run an executable file without an extension. It just replaces your sent bit with a function called shebangtest which will test for a shebang in the first line of the file. If no shebang, then it just runs sent. I also added a few more extensions to the extension list.
2018-10-15 00:15:33 -04:00

59 lines
1.4 KiB
Bash
Executable file

#!/bin/sh
# This script will compile or run another finishing operation on a document. I
# have this script run via vim/emacs.
#
# tex files: Compiles to pdf, including bibliography if necessary
# md files: Compiles to pdf via pandoc
# rmd files: Compiles via R Markdown
# 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"
# config.h files: (For suckless utils) recompiles and installs program.
# all others: run `sent` to show a presentation
oridir=$(pwd)
file=$(readlink -f "$1")
dir=$(dirname "$file")
base="${file%.*}"
shebang=$(sed -n 1p $file)
cd $dir
textype() { \
command="pdflatex"
( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex"
$command --output-directory="$dir" "$base" &&
grep -i addbibresource "$file" &&
biber --input-directory "$dir" "$base" &&
$command --output-directory="$dir" "$base" &&
$command --output-directory="$dir" "$base"
}
shebangtest() {
case "$shebang" in
\#\!*) "$file" ;;
*) sent "$file" 2>/dev/null & ;;
esac
}
case "$file" in
*\.rmd) echo "require(rmarkdown); render('$file')" | R --vanilla && mv "$base".pdf "$dir"/pdfs;;
*\.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 ;;
esac
cd $oridir