-
Notifications
You must be signed in to change notification settings - Fork 160
/
arc.sh
executable file
·115 lines (100 loc) · 3.03 KB
/
arc.sh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
# Put a symlink to this script somewhere in your path.
#
# To run an Arc program, pass it in followed by any args to it.
# To open an interactive prompt (REPL), run without args.
# To open a REPL after running a program, pass in the '-i' flag.
# argument parsing
RLWRAP=true
DO_HELP=false
REPL=maybe
while getopts nih opt; do
case $opt in
n)
RLWRAP=false
;;
i)
REPL=definitely
;;
h)
DO_HELP=true
;;
\? )
# error; show usage anyway
DO_HELP=true
;;
esac
done
# remove options from the arguments
shift $((OPTIND - 1))
if [[ $DO_HELP == true ]] ; then
echo "
arc.sh [-n] [-i] [-h] [<file> [<file_args>]]
OPTIONS
-n
No rlwrap for line-editing (useful inside emacs)
-i
Start an interactive session (REPL)
-h
Print help and exit
<file> [<file_args>]
Run the given file, passing to it any file_args. When the file finishes running, start an interactive session (REPL) if '-i' was explicitly provided.
EXAMPLES
Start the Arc REPL:
arc.sh
Start the Arc REPL without any line-editing smarts:
arc.sh -n
Run the file \"x.arc\", passing to it the argument '3':
arc.sh x.arc 3
Run the file \"x.arc\", passing to it the argument '3' -- and then start the Arc REPL:
arc.sh -i x.arc 3
Run the file \"x.arc\", passing to it the arguments '-i' and '3':
arc.sh x.arc -i 3
"
exit 1
fi
# try to suggest solutions to the most common issues people run into
if ! which racket >&/dev/null
then
echo "Please install racket by following the instructions in README.markdown."
exit 1
fi
case $(uname) in
"Darwin")
if ! which greadlink >&/dev/null
then
echo 'Please do "brew install coreutils"'
exit 1
fi
arc_dir=$(dirname "$(greadlink -f "$0")")
if [[ $RLWRAP == true ]] && ! which rlwrap >&/dev/null
then
echo 'Please run "brew install rlwrap"'
echo 'Or run arc without rlwrap: "./arc.sh -n"'
exit 1
fi
;;
"Linux")
arc_dir=$(dirname "$(readlink -f "$0")")
if [[ $RLWRAP == true ]] && ! which rlwrap >&/dev/null
then
echo "Please install rlwrap with your OS's package manager (apt-get, dpkg, rpm, yum, pacman, etc.)"
echo 'Or run arc without rlwrap: "./arc.sh -n"'
exit 1
fi
;;
*)
arc_dir=$(pwd)
esac
if [ $# -gt 0 ]; then
# there's a file given, execute it
load="(aload-with-main-settings (vector-ref (current-command-line-arguments) 0))"
fi
if [[ $REPL == definitely || ( $REPL == maybe && $# -eq 0 ) ]]; then
# start an interactive prompt
if [[ $RLWRAP == true ]]; then
rl='rlwrap --complete-filenames --quote-character "\"" --remember --break-chars "[]()!:~\"" -C arc'
fi
repl="(tl-with-main-settings)"
fi
$rl racket -t "$arc_dir/boot.rkt" -e "(anarki-init-in-main-namespace-verbose) $load $repl" "$@"