Skip to content

Commit dd2b560

Browse files
committed
Add support for global config file
1 parent 73cfc7e commit dd2b560

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Add `o3` model support.
88
- Support custom API urls for OpenAI and Anthropic
99
- Add `--log-level <level>` option for better debugging.
10+
- Add support for global config file.
1011

1112
## 0.0.3
1213

src/eca/config.clj

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
:chat {:welcomeMessage "Welcome to ECA! What you have in mind?\n\n"}
2727
:index {:ignoreFiles [{:type :gitignore}]}})
2828

29-
(def ttl-cache-config-ms 5000)
29+
(defn get-env [env] (System/getenv env))
30+
(defn get-property [property] (System/getenv property))
31+
32+
(def ^:private ttl-cache-config-ms 5000)
3033

3134
(defn ^:private safe-read-json-string [raw-string]
3235
(try
@@ -40,7 +43,16 @@
4043

4144
(def ^:private config-from-envvar (memoize config-from-envvar*))
4245

43-
(defn ^:private config-from-file* [roots]
46+
(defn ^:private config-from-global-file* []
47+
(let [xdg-config-home (or (get-env "XDG_CONFIG_HOME")
48+
(io/file (get-property "user.home") ".config"))
49+
config-file (io/file xdg-config-home "eca" "config.json")]
50+
(when (.exists config-file)
51+
(safe-read-json-string (slurp config-file)))))
52+
53+
(def ^:private config-from-global-file (memoize/ttl config-from-global-file* :ttl/threshold ttl-cache-config-ms))
54+
55+
(defn ^:private config-from-local-file* [roots]
4456
(reduce
4557
(fn [final-config {:keys [uri]}]
4658
(merge
@@ -51,7 +63,7 @@
5163
{}
5264
roots))
5365

54-
(def ^:private config-from-local-file (memoize/ttl config-from-file* :ttl/threshold ttl-cache-config-ms))
66+
(def ^:private config-from-local-file (memoize/ttl config-from-local-file* :ttl/threshold ttl-cache-config-ms))
5567

5668
(defn ^:private deep-merge [& maps]
5769
(apply merge-with (fn [& args]
@@ -70,4 +82,5 @@
7082
(defn all [db]
7183
(deep-merge initial-config
7284
(config-from-envvar)
85+
(config-from-global-file)
7386
(config-from-local-file (:workspace-folders db))))

0 commit comments

Comments
 (0)