Created
March 29, 2022 04:21
-
-
Save whamtet/1fd9ce6a29e162fa19d48441a9b4eacc to your computer and use it in GitHub Desktop.
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
#!/usr/local/bin/planck | |
(require '[planck.shell :refer [sh]]) | |
(require '[cljs.reader :refer [read-string]]) | |
(defn combinations [[head & rest]] | |
(if rest | |
(for [list (combinations rest) | |
item head] | |
(cons item list)) | |
(map list head))) | |
(defn format-groups [format-strs args] | |
(loop [done [] | |
[format-str & format-strs] format-strs | |
[arg & other-args :as args] args] | |
(if format-str | |
(if (.includes format-str "%s") | |
(recur | |
done | |
(cons (.replace format-str "%s" (str arg)) format-strs) | |
other-args) | |
;; move onto next group | |
(recur | |
(conj done format-str) | |
format-strs | |
args)) | |
done))) | |
(let [args *command-line-args* | |
[f args] (if (-> args first (= "-d")) [prn (rest args)] [sh args]) | |
{format-strs false | |
arrays true} (group-by #(.startsWith % "[") args) | |
arrays (map read-string arrays)] | |
(doseq [combination (combinations arrays)] | |
(apply f (format-groups format-strs combination)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment