Skip to content

Instantly share code, notes, and snippets.

@lilactown
Last active June 18, 2019 09:52
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lilactown/a67bb2dc9295d7990d9f8525f478457c to your computer and use it in GitHub Desktop.
Save lilactown/a67bb2dc9295d7990d9f8525f478457c to your computer and use it in GitHub Desktop.
Start a Clojure(Script) REPL with rebel-readline and any other dependencies you want to include
# Add these to your .bash_profile / .zshrc / etc.
# Starts a Clojure repl
function rebel-clj() {
clojure -Sdeps "{:deps {com.bhauman/rebel-readline {:mvn/version \"0.1.4\"} $@}}" -m rebel-readline.main
}
# Starts a browser REPL
function rebel-cljs() {
clojure -Sdeps "{:deps {com.bhauman/figwheel-main {:mvn/version \"0.1.7\"} com.bhauman/rebel-readline-cljs {:mvn/version \"0.1.4\"} $@}}" -m figwheel.main
}
@lilactown
Copy link
Author

lilactown commented Sep 4, 2018

To download and load a dependency:

rebel-clj 'clj-time {:mvn/version "0.14.2"}'

You can put many dependencies in as one string, they just get inserted directly into the :deps map:

rebel-clj 'clj-time {:mvn/version "0.14.2"} org.clojure/core.async {:mvn/version "0.4.474"}'

@timvisher
Copy link

I made it so you can use the lein coordinates easily. Thanks for the idea! :)

_rebl_translate_lein_dep() {
    local lein_dep lein_dep_name lein_dep_version

    lein_dep=$1

    IFS=' ' read -r lein_dep_name lein_dep_version <<<"$lein_dep"

    lein_dep_name="${lein_dep_name/[/}"
    lein_dep_version="${lein_dep_version/]/}"

    echo "${lein_dep_name} {:mvn/version ${lein_dep_version}}"
}

rebl() {
    echo 'ALPHA' >&2
    local -a deps
    while [[ -n $1 ]]
    do
        read -r line < <(_rebl_translate_lein_dep "$1")
        shift
        deps+=($line)
    done
    clojure -Sdeps '{:deps {com.bhauman/rebel-readline {:mvn/version "0.1.4"} '"${deps[*]}"'}}' \
            -m rebel-readline.main
}
$ rebl '[clj-http "3.9.1"]' '[cheshire "5.8.1"]'
ALPHA
[Rebel readline] Type :repl/help for online help info
user=> (require '[clj-http.client :as c])
nil
user=> (require '[cheshire.core :as json])
nil
user=>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment