Skip to content

Instantly share code, notes, and snippets.

@yogsototh
Created August 18, 2024 16:04
Show Gist options
  • Save yogsototh/dc16e3213115c8305720f8c74d4a8297 to your computer and use it in GitHub Desktop.
Save yogsototh/dc16e3213115c8305720f8c74d4a8297 to your computer and use it in GitHub Desktop.
Header to put in a file to write a script but use Clojure
#!/bin/bash # -*- mode: Clojure; -*-
#_(
#_DEPS is same format as deps.edn. Multiline is okay.
DEPS='
{:deps {
clj-http/clj-http {:mvn/version "3.12.3"}
cheshire/cheshire {:mvn/version "5.11.0"}
}}
'
#_You can put other options here
OPTS='
-J-Xms4m -J-Xmx256m
'
#_Install Clojure if not present on the system (java is needed though)
LOCAL_CLOJURE_DIR="$HOME/.local/share/clojure"
CLOJURE="$LOCAL_CLOJURE_DIR/bin/clojure"
if [[ ! -x "$LOCAL_CLOJURE_DIR/bin/clojure" ]]; then
[[ ! -d "$LOCAL_CLOJURE_DIR" ]] && mkdir -p "$LOCAL_CLOJURE_DIR"
pushd "$LOCAL_CLOJURE_DIR"
#_Using Posix instructions https://clojure.org/guides/install_clojure#_posix_instructions
curl -L -O https://github.com/clojure/brew-install/releases/latest/download/posix-install.sh
chmod +x posix-install.sh
./posix-install.sh -p $PWD
popd
fi
exec $CLOJURE $OPTS -Sdeps "$DEPS" -M "$0" "$@"
)
(ns my-program
(:require [clj-http.client :as client]
[clojure.pprint :as pp]
[clojure.java.io :as io]
[clojure.java.shell :refer [sh]]))
(defn -main [& args]
(pp/pprint args))
(apply -main *command-line-args*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment