#! /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") 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="$(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 } 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 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