run Clojure scripts with dependencies

#!/usr/bin/env inlein

'{:dependencies [[org.clojure/clojure "1.8.0"]
                 [amazonica "0.3.51"]]}

(require '[ :as s3])

(def bucket-name (first *command-line-args*))

(when-not bucket-name
  (println "Usage:" (System/getProperty "$0") "s3-bucket")
  (System/exit 1))

(let [objs (:object-summaries
            (s3/list-objects :bucket-name bucket-name))]
  (doseq [{:keys [key size]} objs
          :when (pos? size)]
    (println key)))

If you've installed Leiningen before, the installation steps should be familiar:

  1. Make sure you have a Java JDK version 7 or later
  2. Download the latest version of the inlein program
  3. Place it on your $PATH where your shell can find it (eg. ~/bin)
  4. Set it to be executable (chmod a+x ~/bin/inlein)
  5. The first time you run a script (inlein file or ./file), inlein will set up and download the necessary files

Full documentation on how to use Inlein can be found at the Getting Started page on the Inlein wiki. It covers installation, usage, command line options and general tips.

The documentation does not cover learning Clojure itself, but fortunately, good Clojure documentation is easily available.