-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompiler
More file actions
executable file
·53 lines (43 loc) · 1.22 KB
/
compiler
File metadata and controls
executable file
·53 lines (43 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
# Compile or execute a file based on extension or shebang.
set -eu
[ "$#" -eq 1 ] || {
printf 'Usage: %s <file>\n' "$0" >&2
exit 1
}
file=$(readlink -f "$1")
[ -f "$file" ] || {
printf 'File not found: %s\n' "$1" >&2
exit 1
}
dir=$(dirname "$file")
base="${file%.*}"
cd "$dir"
textype() {
command_name='pdflatex'
if sed -n '1,5p' "$file" | grep -iq 'xelatex'; then
command_name='xelatex'
fi
"$command_name" --output-directory="$dir" "$file"
if grep -iq 'addbibresource' "$file"; then
biber --input-directory "$dir" "$base"
"$command_name" --output-directory="$dir" "$file"
fi
"$command_name" --output-directory="$dir" "$file"
}
case "$file" in
*.ms) refer -PS -e "$file" | groff -me -ms -kejpt -T pdf > "$base".pdf ;;
*.mom) refer -PS -e "$file" | groff -mom -kejpt -T pdf > "$base".pdf ;;
*.tex) textype ;;
*.md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;;
*.c) gcc "$file" -o "$base" && "$base" ;;
*.py) python3 "$file" ;;
*)
if sed -n '1s/^#!//p' "$file" | grep -q .; then
"$file"
else
printf 'No build rule for file: %s\n' "$file" >&2
exit 1
fi
;;
esac