Last active
August 19, 2020 12:40
-
-
Save borkdude/63a86a04f5d97aae4825326c0309dad2 to your computer and use it in GitHub Desktop.
shell macro
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
(require '[clojure.java.shell :as sh] | |
'[clojure.string :as str]) | |
(defn format-arg [arg] | |
(cond | |
(symbol? arg) (str arg) | |
(seq? arg) (let [f (first arg)] | |
(if (and (symbol? f) (= "unquote" (name f))) | |
(second arg) | |
arg)) | |
:else (pr-str arg))) | |
(defmacro $ [& args] | |
`(let [command# (str/join " " ~(mapv format-arg args))] | |
(sh/sh "bash" "-c" command#))) | |
(let [dir "src" | |
pat "e"] | |
(-> ($ find ~dir | grep ~pat) | |
:out | |
println)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage on my machine: