Skip to content

Instantly share code, notes, and snippets.

@whamtet
Created March 29, 2022 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whamtet/1fd9ce6a29e162fa19d48441a9b4eacc to your computer and use it in GitHub Desktop.
Save whamtet/1fd9ce6a29e162fa19d48441a9b4eacc to your computer and use it in GitHub Desktop.
#!/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