Scripting with clj

I’m trying to write my scripts in Clojure tool with new deps and CLI. But instead of using it globally with shebang, I prefer running projects locally based on my habits from Node.js projects.

I did that in my workflow recently by adding cli/ folder and adding it to :paths ["cli/"]. Then I can call from command line:

clj -m build.task-name

Not short enough but available for my case. Then combining with sh and I got my scripts:

(ns build.upload
  (:require [clojure.java.shell :refer [sh]]))

(defn sh! [command]
  (println command)
  (println (sh "bash" "-c" command)))

(defn -main []
  (echo "run task")
  (shutdown-agents))

It’s not bad but I there are something I need to become faster:

  • a shorter form of invoking functions.
  • I would like to call specific functions for each task(actually shadow-cljs can do that).
  • starts faster, always wanted. and better error messages.

I don’t use many dependencies yet. However I do want to see more tasks I can import and use in my scripts. Writing Bash scripts is a little dirty.

2 Likes