97ae8ca1d0
append `sed` commands instead of piping them (bibinput, bibshow) add dependencies (bibinput, bibshow) break forloop when bulding is done (compiler)
70 lines
1.7 KiB
Bash
Executable File
70 lines
1.7 KiB
Bash
Executable File
#!/bin/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
|
|
# tex : compile via pdflatex (bibtex 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="$(grep '\bibliography' "$file")"
|
|
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
|
|
}
|
|
|
|
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
|
|
break 0
|
|
fi
|
|
done
|
|
|
|
case "$file" in
|
|
*.c*|.h*) make && ./main ;;
|
|
*.mom) refer -PS -e "$file" | pdfmom > "$base.pdf" ;;
|
|
*.tex) texcompile "$base" ; texclear "$file" ;;
|
|
*.py) python "$file" ;;
|
|
*) shebangtest ;;
|
|
esac
|