Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active November 2, 2015 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfikes/b701336b52b1a72a0ce9 to your computer and use it in GitHub Desktop.
Save mfikes/b701336b52b1a72a0ce9 to your computer and use it in GitHub Desktop.
macro git version

src/foo/macros.clj:

(ns foo.macros
  (:require [clojure.java.shell :as shell]
            [clojure.string :as string]))

(defmacro get-git-version []
  (-> (shell/sh "bash" "-c" "git log --oneline -n 1")
         :out
         (string/split #" ")
         first))

src/foo/core.cljs:

(ns foo.core
  (:require-macros [foo.macros :refer [get-git-version]]))

(def git-version (get-git-version))

REPL interaction:

cljs.user=> (require 'foo.core)
nil
cljs.user=> foo.core/git-version
"1f5c0d8"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment