2021-02-12 23:20:57 +01:00
|
|
|
#!/usr/bin/env sh
|
2020-05-20 18:34:34 +02:00
|
|
|
|
|
|
|
######################################################################
|
2021-02-14 19:07:45 +01:00
|
|
|
# @author : swytch (adapted from Luke Smith - lukesmith.xyz)
|
|
|
|
# @file : compiler
|
2021-02-15 00:37:34 +01:00
|
|
|
# @license : GPLv3
|
2021-02-14 19:07:45 +01:00
|
|
|
# @created : Wednesday May 20, 2020 18:00:51 CEST
|
2020-05-20 18:34:34 +02:00
|
|
|
#
|
2021-02-14 19:07:45 +01:00
|
|
|
# @description : compile or run another finishing operation on a file
|
2020-05-23 15:47:21 +02:00
|
|
|
# groff-mom : compile via pdfmom to a pdf document
|
|
|
|
# c : compile via gcc
|
2021-02-14 19:07:45 +01:00
|
|
|
# config.def.h (suckless) : recompile, install
|
2021-05-21 02:00:03 +02:00
|
|
|
# blocks.def.h (dwmblocks) : recompile, install
|
2020-05-23 15:47:21 +02:00
|
|
|
# tex : compile via pdflatex (bibtex if needed)
|
2020-05-20 18:34:34 +02:00
|
|
|
######################################################################
|
2020-05-06 03:20:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
file=$(readlink -f "$1")
|
|
|
|
dir=$(dirname "$file")
|
2020-05-20 17:03:00 +02:00
|
|
|
dirname=$(basename "$dir")
|
2020-05-25 15:04:16 +02:00
|
|
|
base="$(printf "${file%.*}" | awk -F '/' '{printf $NF}')"
|
2020-05-06 03:20:19 +02:00
|
|
|
shebang=$(sed -n 1p "$file")
|
|
|
|
|
|
|
|
cd "$dir" || exit
|
|
|
|
|
|
|
|
shebangtest()
|
|
|
|
{
|
|
|
|
case "$shebang" in
|
|
|
|
\#\!*) "$file" ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:03:00 +02:00
|
|
|
texcompile() { \
|
2022-07-08 15:26:05 +02:00
|
|
|
[ "$base" != "notes" ] && [ -e "main.tex" ] && base="main" && file="$base.tex"
|
2022-05-31 17:24:31 +02:00
|
|
|
cmd="pdflatex"
|
|
|
|
case "$(head -n 1 $file)" in
|
|
|
|
*lua*) cmd="lualatex" ;;
|
|
|
|
esac
|
2020-06-14 16:46:02 +02:00
|
|
|
bibliography="$(grep '\\bibliography' "$file")"
|
2022-05-31 17:24:31 +02:00
|
|
|
|
2020-05-06 03:20:19 +02:00
|
|
|
if [ -n "$bibliography" ]; then
|
2022-05-31 17:24:31 +02:00
|
|
|
$cmd --output-directory="$dir" "$base" &&
|
2020-05-06 03:20:19 +02:00
|
|
|
bibtex "$base" &&
|
2022-05-31 17:24:31 +02:00
|
|
|
$cmd --output-directory="$dir" "$base" &&
|
|
|
|
$cmd --output-directory="$dir" "$base"
|
2020-05-06 03:20:19 +02:00
|
|
|
else
|
2022-05-31 17:24:31 +02:00
|
|
|
$cmd --output-directory="$dir" "$base" &&
|
|
|
|
$cmd --output-directory="$dir" "$base"
|
2020-05-06 03:20:19 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:03:00 +02:00
|
|
|
for tool in $sucklesstools; do
|
|
|
|
if [ "$tool" = "$dirname" ]; then
|
|
|
|
s_build
|
2020-06-14 16:46:02 +02:00
|
|
|
exit 0
|
2020-05-20 17:03:00 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-05-06 03:20:19 +02:00
|
|
|
case "$file" in
|
2021-05-21 02:00:03 +02:00
|
|
|
*blocks.def.h) sudo make clean install ;;
|
|
|
|
*config.def.h) sudo make clean install ;;
|
2020-09-29 00:35:36 +02:00
|
|
|
*.c*|*.h*) make && ./main ;;
|
2020-05-20 17:03:00 +02:00
|
|
|
*.mom) refer -PS -e "$file" | pdfmom > "$base.pdf" ;;
|
|
|
|
*.tex) texcompile "$base" ; texclear "$file" ;;
|
|
|
|
*.py) python "$file" ;;
|
2020-05-06 03:20:19 +02:00
|
|
|
*) shebangtest ;;
|
|
|
|
esac
|