This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.local/bin/compiler
2020-05-06 03:20:19 +02:00

49 lines
1.3 KiB
Bash
Executable File

#! /bin/sh
# This script will compile or run another finishing operation on a document
# It is meant to be run via vim/neovim
# Adapted form the work of Luke Smith (lukesmith.xyz)
# groff-mom files : Compiles via pdfmom to a pdf document
# c files : Compiles via gcc
# config.def.h (-> suckless) recompiles and install the program
# tex files : Compiles via pdflatex (biblatex if needed)
file=$(readlink -f "$1")
dir=$(dirname "$file")
base="$(echo "${file%.*}" | awk -F '/' '{printf $NF}')"
shebang=$(sed -n 1p "$file")
cd "$dir" || exit
shebangtest()
{
case "$shebang" in
\#\!*) "$file" ;;
esac
}
textype() { \
bibliography="$(cat "$file" | grep '\bibliography')"
if [ -n "$bibliography" ]; then
pdflatex --output-directory="$dir" "$base" &&
bibtex "$base" &&
pdflatex --output-directory="$dir" "$base" &&
pdflatex --output-directory="$dir" "$base"
else
pdflatex --output-directory="$dir" "$base" &&
pdflatex --output-directory="$dir" "$base"
fi
texclear "$file"
}
case "$file" in
*config.def.h) sudo make clean install && rm -f config.h ;;
*config.h) echo "" && echo "You should build from config.def.h !" ;;
*\.c*) make && ./main ;;
*\.h*) make && ./main ;;
*\.mom) refer -PS -e "$file" | pdfmom > "$base.pdf" ;;
*\.tex) textype "$base" ;;
*\.py) python "$file" ;;
*) shebangtest ;;
esac