Skip to content

Instantly share code, notes, and snippets.

@tuor713
Created September 25, 2010 01:22
Show Gist options
  • Save tuor713/596336 to your computer and use it in GitHub Desktop.
Save tuor713/596336 to your computer and use it in GitHub Desktop.
(use 'uwh.common.jline)
(use '[clojure.contrib.io :only (file read-lines)])
(def processor (atom identity))
(defn nil-safe [f] #(if (nil? %) % (f %)))
(defn add! [f] (swap! processor #(comp (nil-safe f) %)))
(run
(commands
(transform [f :file]
(doall (map (comp (nil-safe println) @processor)
(read-lines (file f)))))
(reset [] (reset! processor identity))
(include [re :any]
(add! #(if (.matches % (str ".*" re ".*"))
% nil)))
(exclude [re :any]
(add! #(if (.matches % (str ".*" re ".*"))
nil %)))
(replace [re :any s :any]
(add! #(.replaceAll % re s)))
(exit [] (reset! *exit* true))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment