Last active
February 22, 2025 10:41
-
-
Save ericnormand/6bb4562c4bc578ef223182e3bb1e72c5 to your computer and use it in GitHub Desktop.
Boilerplate for running Clojure as a shebang script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#_( | |
#_DEPS is same format as deps.edn. Multiline is okay. | |
DEPS=' | |
{:deps {clj-time {:mvn/version "0.14.2"}}} | |
' | |
#_You can put other options here | |
OPTS=' | |
-J-Xms256m -J-Xmx256m -J-client | |
' | |
exec clojure $OPTS -Sdeps "$DEPS" "$0" "$@" | |
) | |
(println "Hello!") | |
(require '[clj-time.core :as t]) | |
(prn (str (t/now))) | |
(prn *command-line-args*) | |
(println (.. (Runtime/getRuntime) | |
totalMemory)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cp script.clj ~/bin/cljtest2 | |
# ~/bin is on my $PATH | |
$ chmod +x ~/bin/cljtest2 | |
$ time cljtest2 "Yo" "Hey" 1 3 4 - -ff | |
Hello! | |
"2019-03-01T17:22:43.564Z" | |
("Yo" "Hey" "1" "3" "4" "-" "-ff") | |
268435456 | |
real 0m2.073s | |
user 0m6.073s | |
sys 0m0.297s | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just figured out a way to make it even more portable by adding a step that install a specific version of Clojure local to the script.
So with this small block added, your only dependency is java.