#! /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")
dirname=$(basename "$dir")
base="$(echo "${file%.*}" | awk -F '/' '{printf $NF}')"
shebang=$(sed -n 1p "$file")
sucklesstools="$(ls $XDG_CONFIG_HOME/suckless)"
cd "$dir" || exit
shebangtest()
{
case "$shebang" in
\#\!*) "$file" ;;
esac
}
texcompile() { \
bibliography="$(cat "$file" | grep '\bibliography')"
if [ -n "$bibliography" ]; then
pdflatex --output-directory="$dir" "$base" &&
bibtex "$base" &&
pdflatex --output-directory="$dir" "$base"
else
fi
s_build(){
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 !" ;;
exit 0
for tool in $sucklesstools; do
if [ "$tool" = "$dirname" ]; then
s_build
done
*.c*|.h*) make && ./main ;;
*.mom) refer -PS -e "$file" | pdfmom > "$base.pdf" ;;
*.tex) texcompile "$base" ; texclear "$file" ;;
*.py) python "$file" ;;
*) shebangtest ;;