Execute the Clojure REPL command when a file changes


Every time a source file changes, I'd like to run a command in my currently running running clojure repl. This is similar to people running a bash command upon file changes (i.e., rebuilding their project when a file changes). Is this possible?

You can use clojure/tools.namespace and its clojure.tools.namespace.repl/refresh function providing it the :after option pointing to your function:

(refresh :after 'some-ns/some-fn)

From now on tools.namespace will watch your source files and reload relevant namespaces if they change and call your function after reloading.