2020-05-20 18:34:34 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
######################################################################
|
2020-05-23 15:47:21 +02:00
|
|
|
# @author : swytch (adapted from Luke Smith - lukesmith.xyz)
|
|
|
|
# @file : compiler
|
|
|
|
# @license : GPLv3
|
|
|
|
# @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-06 03:20:19 +02:00
|
|
|
base="$(echo "${file%.*}" | awk -F '/' '{printf $NF}')"
|
|
|
|
shebang=$(sed -n 1p "$file")
|
|
|
|
|
2020-05-20 17:03:00 +02:00
|
|
|
sucklesstools="$(ls $XDG_CONFIG_HOME/suckless)"
|
|
|
|
|
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-05-20 19:24:34 +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
|
|
|
|
*config.def.h) sudo make clean install && rm -f config.h ;;
|
|
|
|
*config.h) echo "" && echo "You should build from config.def.h !" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
for tool in $sucklesstools; do
|
|
|
|
if [ "$tool" = "$dirname" ]; then
|
|
|
|
s_build
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-05-06 03:20:19 +02:00
|
|
|
case "$file" in
|
2020-05-20 17:03:00 +02:00
|
|
|
*.c*|.h*) make && ./main ;;
|
|
|
|
*.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
|