Created
September 12, 2016 09:16
-
-
Save slipset/43f3ca729158d33e73865f0b14b367fd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env planck | |
(ns colorblock.core | |
(:require [planck.core :refer [*command-line-args* slurp]] | |
[planck.shell :refer [sh]] | |
[clojure.string :as s])) | |
(def usage-str "USAGE:\ncolorblock example.clj SomeTagName\ncolorblock example.clj SomeTagName [OUTPUT FORMAT]\n") | |
(def pygmentize-opts "style=friendly,fontface=Inconsolata,fontsize=62") | |
(def command (if (= 0 (:exit (sh "type" "-a" "pbcopy"))) | |
["pbcopy"] | |
["xclip" "-selection" "clipboard"])) | |
(defn find-contents [tag contents] | |
(->> contents | |
(drop-while #(not= (str ";;START " tag ) %)) | |
(rest) | |
(take-while #(not= (str ";;END " tag) %)) | |
(s/join "\n"))) | |
(defn do-format [file tag command format] | |
(->> file | |
slurp | |
s/split-lines | |
(find-contents tag) | |
(sh "pygmentize" "-f" format "-O" pygmentize-opts "-l" "clojure" :in) | |
:out | |
(conj command :in) | |
(apply sh) | |
:exit)) | |
(defn usage [args] | |
(when (or (not (seq args)) | |
(seq (filter #(or (= "-h" %) (= "--help" %)) args))) | |
(println usage-str) | |
(planck.core/exit 1))) | |
(defn -main [args] | |
(usage args) | |
(let [format (if (= 3 (count *command-line-args*)) | |
(nth *command-line-args* 2) | |
"rtf")] | |
(planck.core/exit (apply do-format (conj args command format))))) | |
(-main (vec *command-line-args*)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment