commit 56df91d05d8edf72abdf6d85e4b436c59e925716
parent baa07d030311bd80b603417add738ecddbd0be3a
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Tue, 30 Jun 2020 11:33:21 +0200
Remove C compilation, fix shellcheck(1) warnings
Diffstat:
1 file changed, 22 insertions(+), 34 deletions(-)
diff --git a/.local/bin/compile b/.local/bin/compile
@@ -3,12 +3,12 @@ opener=xdg-open
show_help() {
echo "usage: ${0##*/} [OPTIONS] FILE ..."
- echo "will compile each FILE based on its extension."
+ echo "compiles each FILE based on its extension."
echo
echo "OPTIONS are one or more of the following:"
echo " -h show this message"
- echo " -c continuously recompile upon file changes"
- echo " -o open output file after compiling"
+ echo " -c continuously recompile upon file changes (requires entr(1))"
+ echo " -o open output file after compiling (requires ${opener}(1))"
echo " -- do not consider any following args as options"
}
@@ -23,11 +23,13 @@ regeximatch() {
extract_tex_include() {
d="$(grep -v ".*%.*\\${2}" "$1" |
- sed -nE "/.*\\${2}\[*.*\]*\{([^}]*)\}.*/{ s//\1/;p; }")"
+ sed -nE "/.*\\${2}\\[*.*\\]*\\{([^}]*)\\}.*/{ s//\\1/;p; }")"
if [ "$2" = "bibliography" ] && [ -n "$d" ]; then
d="${d%.bib}.bib"
fi
- [ -n "$d" ] && printf '%s\n' "$d" || :
+ if [ -n "$d" ]; then
+ printf '%s\n' "$d"
+ fi
}
find_dependencies() {
@@ -54,7 +56,7 @@ run_compile() {
if [ "$continuous" = 1 ]; then
printf '%s\n' "$2" | entr -s "$1"
else
- eval $1
+ eval "$1"
fi
}
@@ -62,7 +64,7 @@ handle_target() {
base="$(basename "${1%.*}")"
if [ -e "$1" ]; then
case "$1" in
- *\.tex)
+ *.tex)
deps="$1"
deps="$(find_dependencies "$1")"
for d in $deps; do
@@ -77,38 +79,29 @@ handle_target() {
else
compile_string="pdflatex '$1' && pdflatex '$1'"
fi
- printf 'compile_string=%s\n' "$compile_string"
run_compile "$compile_string" "$deps"
- [ "$open" = 1 ] && $opener "${1%.tex}.pdf" || :
- ;;
- *\.gp)
- run_compile "gnuplot '$1'" "$1"
- ;;
- *\.c)
if [ "$open" = 1 ]; then
- run_compile "cc $CFLAGS $LDFLAGS -std=c99 -pedantic -Wall -O2 -g '$1' -o '${1%.*}' && ./${1%.*}" "$1"
- else
- run_compile "cc $CFLAGS $LDFLAGS -std=c99 -pedantic -Wall -O2 -g '$1' -o '${1%.*}'" "$1"
+ $opener "${1%.tex}.pdf"
fi
;;
- *\.[0-9])
+ *.gp)
+ run_compile "gnuplot '$1'" "$1";;
+ *.[0-9])
out="$(basename "${base}").pdf"
if [ "$open" = 1 ]; then
run_compile "refer -PS -e '$1' | groff -mandoc -T pdf > '$out' && $opener '$out'" "$1"
else
run_compile "refer -PS -e '$1' | groff -mandoc -T pdf > '$out'" "$1"
- fi
- ;;
- *\.mom)
+ fi;;
+ *.mom)
out="$(basename "${base}").pdf"
if [ "$open" = 1 ]; then
run_compile "pdfmom '$1' > '$out' && $opener '$out'" "$1"
else
run_compile "pdfmom '$1' > '$out'" "$1"
- fi
- ;;
+ fi;;
*)
- die "File type $extension not supported\n";;
+ die "File type ${1##*.} not supported\\n";;
esac
else
die "cannot read $1"
@@ -121,21 +114,16 @@ while :; do
case "$1" in
-h|-\?)
show_help
- exit 0
- ;;
+ exit 0;;
-c)
- continuous=1
- ;;
+ continuous=1;;
-o)
- open=1
- ;;
+ open=1;;
--) # end all options
shift
- break
- ;;
+ break;;
-?*)
- die 'unknown option specified'
- ;;
+ die 'unknown option specified';;
*) # No more options
break
esac