Skip to content

Instantly share code, notes, and snippets.

@borkdude

borkdude/macro.clj

Last active Aug 19, 2020
Embed
What would you like to do?
shell macro
(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))
@borkdude

This comment has been minimized.

Copy link
Owner Author

@borkdude borkdude commented May 12, 2020

Usage on my machine:

$ clj /tmp/macro.clj
src/dre/gateway/entrez.clj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.