#! /bin/sh # This script will compile or run another finishing operation on a document # It is meant to be run via vim/neovim # Adapted form the work of Luke Smith (lukesmith.xyz) # groff-mom files : Compiles via pdfmom to a pdf document # c files : Compiles via gcc # config.def.h (-> suckless) recompiles and install the program # tex files : Compiles via pdflatex (biblatex if needed) file=$(readlink -f "$1") dir=$(dirname "$file") base="$(echo "${file%.*}" | awk -F '/' '{printf $NF}')" shebang=$(sed -n 1p "$file") cd "$dir" || exit shebangtest() { case "$shebang" in \#\!*) "$file" ;; esac } textype() { \ bibliography="$(cat "$file" | grep '\bibliography')" 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 texclear "$file" } 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 !" ;; *\.c*) make && ./main ;; *\.h*) make && ./main ;; *\.mom) refer -PS -e "$file" | pdfmom > "$base.pdf" ;; *\.tex) textype "$base" ;; *\.py) python "$file" ;; *) shebangtest ;; esac