2021-02-12 23:20:57 +01:00
|
|
|
#!/usr/bin/env sh
|
2020-05-20 18:34:34 +02:00
|
|
|
|
|
|
|
######################################################################
|
2020-05-23 15:47:21 +02:00
|
|
|
# @author : swytch (adapted from Luke Smith - lukesmith.xyz)
|
|
|
|
# @file : compiler
|
2020-06-25 18:19:40 +02:00
|
|
|
# @license : MIT
|
2020-05-23 15:47:21 +02:00
|
|
|
# @created : Wednesday May 20, 2020 18:00:51 CEST
|
2020-05-20 18:34:34 +02:00
|
|
|
#
|
2020-05-23 15:47:21 +02:00
|
|
|
# @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
|
|
|
|
# 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")
|
|
|
|
|
2020-06-25 18:17:42 +02:00
|
|
|
sucklesstools="$(ls $HOME/.local/src/suckless)"
|
2020-05-20 17:03:00 +02:00
|
|
|
|
2020-05-06 03:20:19 +02:00
|
|
|
cd "$dir" || exit
|
|
|
|
|
|
|
|
shebangtest()
|
|
|
|
{
|
|
|
|
case "$shebang" in
|
|
|
|
\#\!*) "$file" ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:03:00 +02:00
|
|
|
texcompile() { \
|
2020-06-14 16:46:02 +02:00
|
|
|
bibliography="$(grep '\\bibliography' "$file")"
|
2020-05-06 03:20:19 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:03:00 +02:00
|
|
|
s_build(){
|
|
|
|
case "$file" in
|
2020-06-18 15:58:08 +02:00
|
|
|
*config.def.h) sudo make clean install ;;
|
2020-06-14 16:46:02 +02:00
|
|
|
*config.h) printf "\nYou should build from config.def.h !" && exit 1 ;;
|
|
|
|
*) printf "\nI guess you lost yourself ? Please build from config.def.h !" && exit 1 ;;
|
2020-05-20 17:03:00 +02:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
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-02-13 21:37:24 +01:00
|
|
|
*blocks.def.h) make && 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
|