From 08a332d0daa13e52e4c8ae9bf2dbcb6408041a34 Mon Sep 17 00:00:00 2001 From: davidpkj Date: Wed, 15 Mar 2023 14:09:28 +0100 Subject: Cleaned up some scripts --- scripts/.local/bin/personal/compile | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'scripts/.local/bin/personal/compile') diff --git a/scripts/.local/bin/personal/compile b/scripts/.local/bin/personal/compile index 028ae11..c5643b8 100755 --- a/scripts/.local/bin/personal/compile +++ b/scripts/.local/bin/personal/compile @@ -1,8 +1,10 @@ #!/bin/bash # A script to compile any (here defined) type of text file to a target format -# Depends on: bash, basename, pdflatex, pandoc, asciidoctor +# Depends on: bash, basename, pdflatex, pandoc, asciidoctor, make # By David Penkowoj, 2021/08/02 +# +# Usage: compile {file} [--no-make] # Function to compile .md to .pdf files ADOC_TO_HTML() { @@ -36,16 +38,35 @@ MD_TO_PDF() { sed '/^!.*/d' "$1" > "$TMP" && # This enables comments with "!" sed 's/^\\!/!/g' "$TMP" "$TMP" && # This enables escaping with "\!" - pandoc "$TMP" -o "$2.pdf" && + pandoc "$TMP" --template "$HOME/documents/templates/abgaben.latex" -o "$2.pdf" && printf "Successfully compiled %s to %s\n" "$1" "$2.pdf" || printf "[ Error ] Couldn't compile %s\n" "$1" } +# Function to run the make command if possible +RUN_MAKE() { + cd "$1" && + make auto && + printf "Successfully made project\n" || + printf "[ Error ] Couldn't make project\n" +} + # Check if file exists if [[ -e "$1" ]]; then # Determine filename and extension FILENAME="$(basename -- "$1")" EXTENSION="${FILENAME##*.}" + FILEPATH="$(pwd)/$1" + DIRECTORY="${FILEPATH%/*}" + + # If make file exists, run make and exit + if [[ -e "$DIRECTORY/makefile" ]] || [[ -e "$DIRECTORY/Makefile" ]]; then + echo "$2" + if [[ "$2" != "--no-make" ]]; then + RUN_MAKE "$DIRECTORY" + exit 0 + fi + fi # Check if there is a extension at all if [[ "$FILENAME" == "$EXTENSION" ]]; then -- cgit v1.2.3