-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env bb | ||
(ns missing-in-brewfiles | ||
(:require [babashka.fs :as fs] | ||
[babashka.process :as p] | ||
[clojure.set :as set] | ||
[clojure.string :as str])) | ||
|
||
(def target-brewfile (fs/path (fs/xdg-config-home) "ansible" "brews")) | ||
|
||
(defn run [& args] | ||
(let [{:keys [out err exit]} (apply p/sh args)] | ||
(if (zero? exit) | ||
(str/trim out) | ||
(throw (ex-info (str/trim err) {:babashka/exit exit}))))) | ||
|
||
(defn list-actual-formulas [] | ||
(when-let [formulae-stdout (run ["brew" "list" "-1" "--formula" "--installed-on-request"])] | ||
(when-let [formulae (str/split-lines formulae-stdout)] | ||
formulae))) | ||
|
||
(defn list-target-formulas [] | ||
(fs/read-all-lines target-brewfile)) | ||
|
||
(defn missing-in-right [left right] | ||
(vec (set/difference (set left) (set right)))) | ||
|
||
(defn -main [& _] | ||
;; print name of target file to stderr to prevent it being copied when piping to pbcopy | ||
(binding [*out* *err*] | ||
(println "Installed brews missing in brewfile:" (str target-brewfile))) | ||
|
||
(let [actual-formulas (list-actual-formulas) | ||
target-formulas (list-target-formulas) | ||
missing-formulas (missing-in-right actual-formulas target-formulas)] | ||
(doseq [formula (sort missing-formulas)] | ||
(println formula)))) | ||
|
||
(when (= *file* (System/getProperty "babashka.file")) | ||
(apply -main *command-line-args*)) | ||
|
||
(comment | ||
|
||
|
||
(-main) | ||
|
||
|
||
;; | ||
) |