Clojure Startup time is not ideal for day to day scripting with it. But in case you do want to run Clojure scripts, it is possible.
We need to use the “lein exec” plugin to leiningen. Edit ~/.lein/profiles.clj and add these codes:
1 |
{:user {:plugins [[lein-exec "0.3.4"]]}} |
Now the next time you run any leiningen commands, it would install the plugin. You can now execute single file clojure programs by:
1 |
lein exec main.clj |
For more convenience, I added this to my .zshrc:
1 |
alias clojure="lein exec" |
Now I can do this:
1 2 |
$ clojure main.clj Hello World |
You can also use “lein exec” for shebang, like this:
1 2 3 |
#!/usr/bin/env lein exec (println "Hello World") |
Make the file executable and run it like:
1 2 |
$ chmod a+x main.clj $ ./main.clj |