-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun
executable file
·51 lines (45 loc) · 1.32 KB
/
run
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
#!/bin/zsh
# Copyright 2024 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
# Runs an Advent of Code program, with interpreter determined by filename.
# Usage: run [-v] day0/day0.ps day0/input.example.txt day0/input.actual.txt
# run day0/day0.lang checks for a runner script of the form day0/day0lang.sh
# and uses that if the language doesn't have special support. If no runner
# script is found, the named file must be executable.
basedir=${0:h}
if [[ $1 == -v ]]; then
verbose=(-v)
shift
else
verbose=()
fi
if [[ $# -eq 0 ]]; then
print -u 2 "Usage: $0 dayX/file dayX/input.example.txt ..."
exit 1
fi
program="$1"
shift
if [[ ! -f "$program" ]]; then
print -u 2 "$program file not found"
exit 1
fi
case "$program" in
(*.ps) cmd=(gsnd -q -dNOSAFER "-I$basedir" -- "$program" $verbose) ;;
(*.fs) cmd=(gforth -e "${#verbose} constant verbose" "$program" -e bye) ;;
(*.go) cmd=(go run "$program" "${program:h}/runner.go" $verbose) ;;
(*)
runner=${program:r}${program:e}.sh
if [[ -x "$runner" ]]; then
cmd=("$runner" $verbose)
elif [[ -x "$program" ]]; then
cmd=("$program" $verbose)
else
print -u 2 "Don't know how to run $program"
exit 1
fi
;;
esac
exec $cmd "$@"