Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rnesytov/b944bf9f681b0c42519cd0b6ab8f44e5 to your computer and use it in GitHub Desktop.
Save rnesytov/b944bf9f681b0c42519cd0b6ab8f44e5 to your computer and use it in GitHub Desktop.
(ns git-example
(:require [clojure.java.shell :as shell]
[clojure.string :as string]))
(defn run-command [command & {:keys [directory] :or {directory (System/getProperty "user.dir")}}]
(shell/with-sh-dir directory
(shell/sh "sh" "-c" command)))
(defn resolve-command [command & [args]]
(reduce
(fn [command arg-key]
(string/replace command (str "%" (name arg-key)) (arg-key args)))
command
(keys args)))
(defn wrapper [command]
(fn [path & [args]]
(let [result (run-command (resolve-command command args) :directory path)]
(if (zero? (:exit result))
(:out result)
false))))
(defmacro defgit [alias command]
`(def ~(symbol (str alias)) (wrapper ~command)))
(defgit pull "git pull")
(defgit commit "git commit -a -m %message")
(pull "/Path/To/My/Repo/")
(commit "/Path/To/My/Repo/" {:message "My commit message"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment