This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.local/bin/compiler

71 lines
1.9 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env sh
######################################################################
2021-02-14 19:07:45 +01:00
# @author : swytch (adapted from Luke Smith - lukesmith.xyz)
# @file : compiler
# @license : GPLv3
2021-02-14 19:07:45 +01:00
# @created : Wednesday May 20, 2020 18:00:51 CEST
#
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
# blocks.def.h (dwmblocks) : recompile, install
2020-05-23 15:47:21 +02:00
# tex : compile via pdflatex (bibtex if needed)
######################################################################
2020-05-06 03:20:19 +02:00
file=$(readlink -f "$1")
dir=$(dirname "$file")
dirname=$(basename "$dir")
base="$(printf "${file%.*}" | awk -F '/' '{printf $NF}')"
2020-05-06 03:20:19 +02:00
shebang=$(sed -n 1p "$file")
sucklesstools="$(ls $HOME/.local/src/suckless)"
2020-05-06 03:20:19 +02:00
cd "$dir" || exit
shebangtest()
{
case "$shebang" in
\#\!*) "$file" ;;
esac
}
texcompile() { \
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
}
s_build(){
case "$file" in
2020-06-18 15:58:08 +02:00
*config.def.h) sudo make clean install ;;
*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 ;;
esac
}
for tool in $sucklesstools; do
if [ "$tool" = "$dirname" ]; then
s_build
exit 0
fi
done
2020-05-06 03:20:19 +02:00
case "$file" in
*blocks.def.h) make && sudo make clean install ;;
*.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