summaryrefslogtreecommitdiff
path: root/mac/.local/bin/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'mac/.local/bin/compiler')
-rwxr-xr-xmac/.local/bin/compiler84
1 files changed, 84 insertions, 0 deletions
diff --git a/mac/.local/bin/compiler b/mac/.local/bin/compiler
new file mode 100755
index 0000000..bf8b443
--- /dev/null
+++ b/mac/.local/bin/compiler
@@ -0,0 +1,84 @@
+#!/bin/sh
+
+# This script will compile or run another finishing operation on a document. I
+# have this script run via Vim.
+# # tex files: Compiles to pdf, including bibliography if necessary
+# md files: Compiles to pdf via pandoc
+# rmd files: Compiles via R Markdown
+# c files: Compiles via whatever compiler is set to cc. Usually gcc.
+# Use make if Makefile exists.
+# py files: runs via python command
+# go files: compiles and runs with "go run"
+# config.def.h files: (For suckless utils) recompiles and installs program.
+# all others: run `sent` to show a presentation
+
+file=$(readlink -f "$1")
+ext="${file##*.}"
+dir=${file%/*}
+base="${file%.*}"
+
+cd "$dir" || exit
+
+Ifinstalled() {
+ command -v "$1" >/dev/null || { notify-send "📦 <b>$1</b> must be installed for this function." && exit 1; }
+}
+
+pandoccmd() {
+ Ifinstalled pdflatex && pandoc -V geometry:margin=4cm -f markdown-implicit_figures "$1" -o "${2}.pdf" ||
+ Ifinstalled groff && pandoc "${1}" -t ms --pdf-engine-opt=-p -o "${2}.pdf"
+}
+
+pandocorg() { pandoccmd "$file" "$base"; }
+
+compilec() { [ -f "${dir}/Makefile" ] && make || cc "$file" -o "$base" && "$base"; }
+
+case "${ext}" in
+[0-9]) preconv "$file" | refer -PS -e | groff -mandoc -T pdf >"$base".pdf ;;
+apl) apl -f "$file" ;;
+c) compilec ;;
+cob) cobc -x -o "$base" "$file" && "$base" ;;
+config.h) make && sudo make install ;;
+cpp) g++ "$file" -o "$base" && "$base" ;;
+cs) mcs "$file" && mono "$base".exe ;;
+docx | *\.doc)
+ Ifinstalled libreoffice && lowriter --convert-to pdf "$file" && exit
+ Ifinstalled pandoc && pandoccmd "$file" "$base" && exit
+ ;;
+dot | *\.gv) dot -Tsvg "$file" | convert svg:- "$base".eps ;;
+h) compilec ;;
+html) refreshbrowser ;;
+fnl) fennel --compile "$file" >"$base".lua ;;
+go) go run "$file" ;;
+java) javac "$file" && echo "${base##*/}" | xargs java ;;
+js) node "$file" ;;
+m) octave "$file" ;;
+md)
+ pandoc "$file" -s --pdf-engine=xelatex -V geometry:margin=2cm -o "${base}.pdf" || {
+ [ -x "$(command -v lowdown)" ] &&
+ lowdown --parse-no-intraemph "${file}" -Tms | groff -mpdfmark -ms -kept -T pdf >"${base}.pdf" ||
+ [ -x "$(command -v groffdown)" ] &&
+ groffdown -i "${file}" | groff -T pdf >"${base}.pdf" ||
+ pandoc -t ms --highlight-style="kate" -s -o "${base}.pdf" "${file}"
+ }
+ ;;
+me) groff -Gktes -b -w w -me -T ps "$file" | ps2pdf - >"$base".pdf ;;
+mm) groff -Gktes -b -w w -mm -mpic -T ps "$file" | ps2pdf - >"$base".pdf ;;
+mom) pdfroff -pktes -b -wall -mom -mpdfmark "$file" >"$base".pdf ;;
+ms | *\.groff) preconv "$file" | groff -Tpdf -ktesp -G -ms >"$base".pdf ;;
+org) Ifinstalled pandoc && pandocorg "$file" "$base" && exit ;;
+present) groff -p -e -t -mm -mpresent "$file" | presentps -l | ps2pdf - >"$base".pdf ;;
+ps) ps2pdf "$file" ;;
+py) python "$file" ;;
+[rR]md) Rscript -e "rmarkdown::render('$file', quiet=TRUE)" ;;
+r) R -f "$file" ;;
+rink) rink -f "${file}" ;;
+rkt) racket "$file" ;;
+rs) cargo build ;;
+sass) sassc -a "$file" "$base".css ;;
+scad) openscad -o "$base".stl "$file" ;;
+sent) setsid -f sent "$file" 2>/dev/null & ;;
+tex) latexmk ;;
+tcl) tclsh "$file" ;;
+vim*) vint "$file" ;;
+*) chmod +x "$file" && sed 1q "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;;
+esac