Skip to content

Instantly share code, notes, and snippets.

@borkdude
Last active August 19, 2020 12:40
Show Gist options
  • Save borkdude/63a86a04f5d97aae4825326c0309dad2 to your computer and use it in GitHub Desktop.
Save borkdude/63a86a04f5d97aae4825326c0309dad2 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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