summaryrefslogtreecommitdiff
path: root/vimulti.clj
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-07-06 11:13:43 +0800
committereltrac <hi@eltr.ac>2026-07-06 11:13:43 +0800
commitd6fbd70a771ec1200f6e6b781df3368f1ff8380f (patch)
treee657503a40b12def523789da7b19fe276c10db12 /vimulti.clj
parent6e7eee1afd93b7f1089119c56f30131d81dd60d9 (diff)
support local config
Diffstat (limited to 'vimulti.clj')
-rw-r--r--vimulti.clj39
1 files changed, 29 insertions, 10 deletions
diff --git a/vimulti.clj b/vimulti.clj
index 4775f11..38c87c6 100644
--- a/vimulti.clj
+++ b/vimulti.clj
@@ -5,11 +5,30 @@
'[clojure.edn :as edn]
'[clojure.string :as str])
-(def default-config
- {:editor-command "nvim"})
+(def default-config
+ {:editor-command "nvim"
+ :default-target "nvim:"
+ :aliases []})
;; configuration helpers
-(defn- config-path []
+(defn- deep-merge [v & vs]
+ (letfn [(rec-merge [v1 v2]
+ (if (and (map? v1) (map? v2))
+ (merge-with deep-merge v1 v2)
+ v2))]
+ (if (some identity vs)
+ (reduce #(rec-merge %1 %2) v vs)
+ (last vs))))
+
+(defn- init-config [path]
+ (when-not (fs/exists? path)
+ (fs/create-dirs (fs/parent path))
+ (fs/create-file path)
+ (spit path default-config))
+ path)
+
+;;; global config
+(defn- global-config-path []
(let [env-vimnulti-config (System/getenv "VIMULTI_CONFIG")
env-xdg-config-home (System/getenv "XDG_CONFIG_HOME")
config-filename "config.edn"]
@@ -18,14 +37,14 @@
(str env-xdg-config-home "/vimulti/" config-filename)
config-filename))))
-(defn- init-config [path]
- (when-not (fs/exists? path)
- (fs/create-dirs (fs/parent path))
- (fs/create-file path)
- (spit path default-config))
- path)
+(def global-config (-> (global-config-path)
+ init-config
+ slurp
+ edn/read-string))
-(def config (-> (config-path) init-config slurp edn/read-string))
+;;; load local config
+(def config (cond-> global-config
+ (fs/exists? "vimulti.edn") (deep-merge (-> "vimulti.edn" slurp edn/read-string))))
;; git helpers
(defn- get-current-branch [dir]