commit a597e5473f646c20639af0ee19d3af2a3fe53a86
parent d34b39258fa8f93153758e965d86f3dbb4318ab0
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Thu, 28 Nov 2019 11:02:51 +0100
Add compile script for latex and gnuplot
Diffstat:
A | .local/bin/compile | | | 111 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 111 insertions(+), 0 deletions(-)
diff --git a/.local/bin/compile b/.local/bin/compile
@@ -0,0 +1,111 @@
+#!/bin/sh
+set -e
+
+version=0.1
+
+show_help() {
+ echo "usage: ${0##*/} [OPTIONS] FILE ..."
+ echo "will compile each FILE based on its extension."
+ echo
+ echo "OPTIONS are one or more of the following:"
+ echo " -h, --help show this message"
+ echo " -v, --version show version and license information"
+ echo " -V, --verbose show verbose information"
+ echo " -c, --continuous continuously recompile upon file changes"
+ echo " -o, --open open output after compiling, only supported for"
+ echo " some file types"
+ echo " -- do not consider any following args as options"
+}
+
+show_version() {
+ echo "${0##*/} version $version"
+ echo "Licensed under the GNU Public License, v3+"
+ echo "written by Anders Damsgaard, anders@adamsgaard.dk"
+ echo "https://src.adamsgaard.dk/dotfiles"
+}
+
+die() {
+ printf '%s\n' "$1" >&2
+ exit 1
+}
+
+run_compile() {
+ base="${2%.*}"
+ if [ "$continuous" = 1 ]; then
+ echo "$2" | entr -s "$1"
+ else
+ eval $1
+ fi
+}
+
+handle_target() {
+ base="$(basename "${1%.*}")"
+ if [ -e "$1" ]; then
+ case "$1" in
+ *\.tex)
+ preview="-pv-"
+ if [ "$open" = 1 ]; then
+ preview="-pv"
+ fi
+ if [ "$continuous" = 1 ]; then
+ latexmk -pvc $preview -pdf -f "$1"
+ else
+ latexmk -pdf $preview -f "$1"
+ fi;;
+ *\.gp)
+ run_compile "gnuplot '$1'" "$1";;
+ *\.[0-9])
+ run_compile "refer -PS -e '$1' | groff -mandoc -T pdf > '$(basename "${base}").pdf'" "$1";;
+ *)
+ (>2 printf "File type %s not supported\n" $extension)
+ exit 1;;
+ esac
+ return 0
+ else
+ die "cannot open $1"
+ fi
+}
+
+verbose=0
+continuous=0
+open=0
+while :; do
+ case "$1" in
+ -h|-\?|--help)
+ show_help
+ exit 0
+ ;;
+ -v|--version)
+ show_version
+ exit 0
+ ;;
+ -V|--verbose)
+ verbose=1
+ ;;
+ -c|--continuous)
+ continuous=1
+ ;;
+ -o|--open)
+ open=1
+ ;;
+ --) # end all options
+ shift
+ break
+ ;;
+ -?*)
+ die 'Error: Unknown option specified'
+ ;;
+ *) # No more options
+ break
+ esac
+ shift
+done
+
+if [ $# -lt 1 ]; then
+ show_help
+ return 1
+else
+ for f in "$@"; do
+ handle_target "$f"
+ done
+fi