Install and use rebel-readline terminal editor for Clojure
Intro
This will be a short, yet hopefully usefull entry.
At some point there comes a moment when you want to evaluate a code snippet, quickly check something, or maybe just run a fast calculation / simulation in you favourite language1, without having to set up a whole development environment.
What you’d typically do in such a case is fire up a REPL directly in the terminal:
$ ~> clojure
Clojure 1.9.0
user=>
… and hack away. But then lets say you want to do some basic code editing:
user=> (while true
#_=> (do :a)^[[D^[[D^[[D
No Sir Ree Bob! You don’t even have basic syntax navigation, let alone fancy capabilities like code completion. That is why I was very happy when Bruce Hauman (of Figwheel fame) announced he created rebel-readline. You can think of it as of a full REPL development experience, one command in the terminal away.
Lets install it
NOTE
We will assume an arbitrary GNU/Linux distrubution for this example and the presence of basic dependencies - bash, curl, rlwrap, and Java.
Assuming you haven’t already, let’s begin by installing Clojure CLI (Clojure + REPL):
curl -O https://download.clojure.org/install/linux-install-1.9.0.358.sh
chmod +x linux-install-1.9.0.358.sh
sudo ./linux-install-1.9.0.358.sh
Now you’re ready to install rebel-readline. Perhaps the easieset way is to add it as a dependency alias. Edit (or create) $HOME/.clojure/deps.end
and paste (or add) there the alias:
{:aliases {:rebel {:extra-deps {com.bhauman/rebel-readline {:mvn/version "0.1.1"}}}}}
You can already start a REPL with rebel powers:
clojure -R:rebel -m rebel-readline.main
…which might be a bit verbose. So let’s create a rebel-readline.sh
script in some directory:
#!/bin/bash
clojure -R:rebel -m rebel-readline.main
Then ahead and make it executable, as well as create a symlink in a directory which is a part of your $PATH
:
sudo chmod a+x rebel-readline.sh
sudo ln -s -f rebel-readline.sh /usr/bin/rebel-readline
And the powerfull and delightfull REPL experience is only a couple of keystrokes away:
$> rebel-readline
[Rebel readline] Type :repl/help for online help info
user=>
Go and play with it!
1: Clojure obviously!