68 lines
1.9 KiB
Bash
Executable File
68 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env sh
|
|
|
|
######################################################################
|
|
# @author : swytch (adapted from Luke Smith - lukesmith.xyz)
|
|
# @file : compiler
|
|
# @license : GPLv3
|
|
# @created : Wednesday May 20, 2020 18:00:51 CEST
|
|
#
|
|
# @description : compile or run another finishing operation on a file
|
|
# groff-mom : compile via pdfmom to a pdf document
|
|
# c : compile via gcc
|
|
# config.def.h (suckless) : recompile, install
|
|
# blocks.def.h (dwmblocks) : recompile, install
|
|
# tex : compile via pdflatex (bibtex if needed)
|
|
######################################################################
|
|
|
|
|
|
file=$(readlink -f "$1")
|
|
dir=$(dirname "$file")
|
|
dirname=$(basename "$dir")
|
|
base="$(printf "${file%.*}" | awk -F '/' '{printf $NF}')"
|
|
shebang=$(sed -n 1p "$file")
|
|
|
|
cd "$dir" || exit
|
|
|
|
shebangtest()
|
|
{
|
|
case "$shebang" in
|
|
\#\!*) "$file" ;;
|
|
esac
|
|
}
|
|
|
|
texcompile() { \
|
|
[ "$base" != "notes" ] && [ -e "main.tex" ] && base="main" && file="$base.tex"
|
|
cmd="pdflatex"
|
|
case "$(head -n 1 $file)" in
|
|
*lua*) cmd="lualatex" ;;
|
|
esac
|
|
bibliography="$(grep '\\bibliography' "$file")"
|
|
|
|
if [ -n "$bibliography" ]; then
|
|
$cmd --output-directory="$dir" "$base" &&
|
|
bibtex "$base" &&
|
|
$cmd --output-directory="$dir" "$base" &&
|
|
$cmd --output-directory="$dir" "$base"
|
|
else
|
|
$cmd --output-directory="$dir" "$base" &&
|
|
$cmd --output-directory="$dir" "$base"
|
|
fi
|
|
}
|
|
|
|
for tool in $sucklesstools; do
|
|
if [ "$tool" = "$dirname" ]; then
|
|
s_build
|
|
exit 0
|
|
fi
|
|
done
|
|
|
|
case "$file" in
|
|
*blocks.def.h) sudo make clean install ;;
|
|
*config.def.h) sudo make clean install ;;
|
|
*.c*|*.h*) make && ./main ;;
|
|
*.mom) refer -PS -e "$file" | pdfmom > "$base.pdf" ;;
|
|
*.tex) texcompile "$base" ; texclear "$file" ;;
|
|
*.py) python "$file" ;;
|
|
*) shebangtest ;;
|
|
esac
|