Skip to content

Commit f6f3936

Browse files
committed
add missing_in_brewfile
1 parent 24628c8 commit f6f3936

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

missing_in_brewfiles.clj

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bb
2+
(ns missing-in-brewfiles
3+
(:require [babashka.fs :as fs]
4+
[babashka.process :as p]
5+
[clojure.set :as set]
6+
[clojure.string :as str]))
7+
8+
(def target-brewfile (fs/path (fs/xdg-config-home) "ansible" "brews"))
9+
10+
(defn run [& args]
11+
(let [{:keys [out err exit]} (apply p/sh args)]
12+
(if (zero? exit)
13+
(str/trim out)
14+
(throw (ex-info (str/trim err) {:babashka/exit exit})))))
15+
16+
(defn list-actual-formulas []
17+
(when-let [formulae-stdout (run ["brew" "list" "-1" "--formula" "--installed-on-request"])]
18+
(when-let [formulae (str/split-lines formulae-stdout)]
19+
formulae)))
20+
21+
(defn list-target-formulas []
22+
(fs/read-all-lines target-brewfile))
23+
24+
(defn missing-in-right [left right]
25+
(vec (set/difference (set left) (set right))))
26+
27+
(defn -main [& _]
28+
;; print name of target file to stderr to prevent it being copied when piping to pbcopy
29+
(binding [*out* *err*]
30+
(println "Installed brews missing in brewfile:" (str target-brewfile)))
31+
32+
(let [actual-formulas (list-actual-formulas)
33+
target-formulas (list-target-formulas)
34+
missing-formulas (missing-in-right actual-formulas target-formulas)]
35+
(doseq [formula (sort missing-formulas)]
36+
(println formula))))
37+
38+
(when (= *file* (System/getProperty "babashka.file"))
39+
(apply -main *command-line-args*))
40+
41+
(comment
42+
43+
44+
(-main)
45+
46+
47+
;;
48+
)

0 commit comments

Comments
 (0)