Created
May 20, 2016 13:56
-
-
Save rnesytov/b944bf9f681b0c42519cd0b6ab8f44e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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