Skip to content

Instantly share code, notes, and snippets.

@cgrand
Last active May 31, 2017 14:11
Show Gist options
  • Save cgrand/2e8ab1c93443663a73e08ec3744f294d to your computer and use it in GitHub Desktop.
Save cgrand/2e8ab1c93443663a73e08ec3744f294d to your computer and use it in GitHub Desktop.
Launch a plain clojure repl according to project.clj without leiningen (most of the time)
#!/bin/bash
# launch a clojure plain repl but with options and classpath matching project.clj
# Except when project.clj changes (and on first launch), lein is not called.
CODE='
(let [p (leiningen.core.project/read)
args (@(var leiningen.core.eval/get-jvm-args) p)
cp (with-out-str (leiningen.classpath/classpath p))]
(print "ARGS=\"")
(apply print args)
(println "\"")
(print "CP=\"")
(print cp)
(println "\""))
'
if [ ! -f "project.clj" ]; then
echo "No project.clj"
exit 1
fi
if [ ! -f ".kein" ] || [ "project.clj" -nt ".kein" ] || [ $0 -nt ".kein" ]; then
lein update-in : assoc :eval-in :leiningen -- run -m clojure.main -e "$CODE" > .kein
fi
source .kein
java $ARGS -cp $CP clojure.main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment