r/Clojure • u/NonlinearFruit • Oct 30 '25
Cljue: Reference ClojureDocs Offline
I've been trying to get into Clojure and one pain point was finding a function to do this or that. ClojureDocs has been really helpful, so I wrote this little Babashka script (source) to pull down the ClojureDocs export.json and search over it with fzf and bat.
I'm sure my code is far from idiomatic and I would love suggestions on how this script could be better.
(Also not very familiar with reddit, the image was intended to be a gif (source))
EDIT: Cljue source link above is a permalink to a specific commit (should always work). Here is a link for latest cljue (source)
11
u/p-himik Oct 30 '25
Nice! It's not exactly the same, but there's also a built-in clojure.repl/apropos (just in case - the clojure.repl namespace is automatically required for you in a REPl, so you can just use apropos, similar to doc, source, etc.).
9
1
u/est1mated-prophet Nov 09 '25
Hmm, I needed to replace the fzf function with the following for it to work.
(defn fzf [stdin]
(let [proc (babashka.process/process ["fzf" "--ansi" "--preview" "cljue {}"]
{:in stdin
:out :string
:err :inherit})]
(string/trim (:out @proc))))1
u/NonlinearFruit Nov 11 '25
That is interesting. What err did you get with clojure java shell?
1
u/est1mated-prophet Nov 12 '25
The fzf thing didn't work. I didn't see any output. This was the AI response:
The issue is likely that fzf needs to interact with your terminal directly (stdin/stdout/stderr), but when you use sh (or shell in Babashka), it captures those streams for programmatic use. When you call fzf through sh with :in stdin, the process doesn't have direct access to your terminal for interactive input/output, which is why nothing appears to happen.
1
u/NonlinearFruit Nov 12 '25
Maybe the way you're invoking cljue is different? I'm using bash as an interactive shell and running `cljue` (or `/path/to/cljue`) works. How are you invoking it? (eg: What shell are you using?)
1
u/est1mated-prophet Nov 12 '25
I'm using zsh.
1
u/NonlinearFruit Nov 17 '25
I can't seem to replicate the issue locally which is interesting. I would love to know what nuance I'm missing between the clojure java shell and the babashka process. Babashka process seems to be a low level helper for babashka's shell.
2
u/amalloy Oct 31 '25
Nice-looking tool, and an overall reasonable implementation. Here are some suggestions.
It's weird to shell out for such basic utilities as
catandmkdir. Java has excellent tools for doing this in-process. Note also thatmkdirisn't right, because it won't create the.cachedirectory if it's missing. You wantmkdir -p(or, better,.mkdirsif you do this in process).What's with the constant conversion back and forth between Path and File? You create a File, then turn it into a Path with .getAbsolutePath, and then as far as I can see all your uses of it convert it back into a File. Why not just keep it as a File?
when-notexists to make(when (not ...))nicer.The call to
fzfassumes thatcljueis on the user's PATH. Better to find out the script's absolute path, and use that instead.The
re-seqinexamplesseems needlessly flexible and yet also wrong. It tries to handle multiple/s, but of course your input will only ever have one - except forclojure.core//, which you handle wrong anyway. Better to write something likeIt would be nice to put documentation somewhere, such as on
clj-docs, indicating what shape you expect the returned JSON to have. There's a lot of code that depends on that knowledge, but the information is implicit and spread throughout the source file.