aboutsummaryrefslogtreecommitdiff
path: root/scripts/.local/bin/personal/compile
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/.local/bin/personal/compile')
-rwxr-xr-xscripts/.local/bin/personal/compile25
1 files changed, 23 insertions, 2 deletions
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