Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Boilerplate for running Clojure as a shebang script
#!/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))
$ 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
$
@kevinjamescasey

This comment has been minimized.

Copy link

commented Mar 17, 2019

What manner of sorcery is this?

@0atman

This comment has been minimized.

Copy link

commented Mar 27, 2019

I love this.

Strong odds that someone with better shell-fu than me could reads the deps directly from the file!

@0atman

This comment has been minimized.

Copy link

commented Mar 27, 2019

Puts me in mind of my native literate programming hack with python: https://gist.github.com/0atman/36574328fdb2d390834c1d878ac4c32f

@kevinjamescasey

This comment has been minimized.

Copy link

commented Apr 6, 2019

What is the deal with the underscores?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.