Last active
July 10, 2022 18:00
-
-
Save pangloss/ca648ea996755347c6e86bd495f9d644 to your computer and use it in GitHub Desktop.
A babashka script to sort through deps.edn aliases
This file contains hidden or 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/bin/env bb | |
(ns aliases | |
(:require [clojure.edn :as edn] | |
[clojure.tools.cli :refer [parse-opts]] | |
[clojure.string :as str])) | |
(defn show-aliases [{:keys [in-string]}] | |
(let [filter-list (if in-string | |
(partial filter (fn [[kw body]] | |
(str/includes? (str kw) in-string))) | |
identity) | |
home (System/getenv "HOME")] | |
(when in-string | |
(println "Filtering by substring: " in-string "\n")) | |
(println "Global keys:\n") | |
(doseq [k (->> (str home "/.clojure/deps.edn") | |
slurp | |
edn/read-string | |
:aliases | |
filter-list | |
keys | |
sort)] | |
(println k)) | |
(println "\nLocal keys:\n") | |
(try | |
(doseq [k (->> "deps.edn" | |
slurp | |
edn/read-string | |
:aliases | |
filter-list | |
keys | |
sort)] | |
(println k)) | |
(catch Exception e (println "No deps.edn file found"))))) | |
(defn -main [& _args] | |
(let [{:keys [options summary] :as opts} | |
(parse-opts *command-line-args* | |
[["-s" "--in-string SUBSTRING" "Find a substring"] | |
["-h" "--help"]]) | |
{:keys [in-string help]} options] | |
(if help | |
(println summary) | |
(show-aliases options)))) | |
(-main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment