Skip to content

Instantly share code, notes, and snippets.

@chrisvest
Created December 6, 2009 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisvest/250278 to your computer and use it in GitHub Desktop.
Save chrisvest/250278 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Runs clojure.
# With no arguments, runs Clojure's REPL.
# Arguments starting with -J are unpack and passed to the JVM.
# Arguments -cp and -classpath are treated specially so we correctly
# build a classpath.
# If rlwrap is found, the java invocation is wrapped in it.
# For other arguments, the first is treated as a script name, the rest
# passed as command-line arguments.
# resolve links - $0 may be a softlink
CP=/usr/local/Cellar/clojure/master/clojure.jar # CLOJURE_JAR_PATH_PLACEHOLDER
JAVA="java"
if [ -n "$CLASSPATH" ]; then
CP="$CLASSPATH:$CP"
fi
if [ -x "`which rlwrap`" ]; then
JAVA="`which rlwrap` $JAVA"
fi
SCRIPT=""
JVM_ARGS=""
SCRIPT_ARGS=""
# Unpack the arguments.
# The 'shift' command maps $2 to $1, and $3 to $2, etc.
while [ $# -gt 0 ]; do
echo $1
case "$1" in
-cp|-classpath)
CP="$CP:$2"
shift
;;
-J*)
ARG=$1
JVM_ARGS="$JVM_ARGS ${ARG:2}" # cuts off the "-J" part
;;
*)
# first arg is the script name, rest are args for the script
if [ -z SCRIPT ]; then
SCRIPT=$1
else
SCRIPT_ARGS="$SCRIPT_ARGS $1"
fi
esac
shift
done
JAVA="$JAVA -cp $CP $JVM_ARGS"
if [ -z "$SCRIPT" ]; then
$JAVA clojure.lang.Repl
else
$JAVA clojure.lang.Script $SCRIPT -- $SCRIPT_ARGS
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment