I just created Tablizer, it’s a little command line tool that takes a URL, fetches the page, finds any <table>
tags, and prints them out as ASCII table (org-mode style).
I first started with lein new tablizer
, but then decided against that and instead just created a deps.edn
and took it from there. I have the say: the experience was great!
You can just put a shebang on top of the file, #!/usr/bin/env clj
, make a Clojure file executable, and bam, you got yourself a command line script. To be honest I didn’t really expect the shebang to work but tried it anyway. Having this “it’s just UNIX” workflow is IMO a big selling point, as people can try out the language using a workflow they are familiar with.
To be able to use CIDER while working on the script I added a bin/cider
shell script, which loads bin/cider.clj
. All together it looks like this
;; deps.edn
{:deps
{org.clojure/clojure {:mvn/version "1.9.0"}
org.slf4j/slf4j-nop {:mvn/version "1.7.25"}
sparkledriver {:mvn/version "0.2.2"}}
:aliases
{:nrepl {:extra-deps {org.clojure/tools.nrepl {:mvn/version "0.2.12"}}}
:cider {:extra-deps {cider/cider-nrepl {:mvn/version "0.15.1"}}}}}
#### bin/cider
#!/bin/bash
clj -R:nrepl:cider bin/cider.clj $* &
sleep 10
emacsclient -e '(cider-connect "localhost" "'${1:-7888}'" "'`pwd`'")'
;; bin/cider.clj
(require '[clojure.tools.nrepl.server :refer [start-server]]
'[cider.nrepl :refer [cider-nrepl-handler]])
(let [port (or (some-> (first *command-line-args*)
(java.lang.Long/parseLong))
7888)]
(start-server :port port :handler cider-nrepl-handler)
(println "Started nREPL on port" port))
It would have been nice to just have the cider.clj
script, but /usr/bin/env
won’t let you pass parameters to clj
. I could have made it a single script with a heredoc or something but splitting it this way seemed less messy.
It’s a little bit of boiler plate, but I think it’s really great to have this kind of “nothing up the sleeves” way of doing things, without all the magic of Lein or boot. It’s not for every occasion, but it’s great as a starting point for learning, for small CLI projects like this one, or if you just want to have that bit of extra control over your setup.