diff options
Diffstat (limited to 'vimulti.clj')
| -rw-r--r-- | vimulti.clj | 39 |
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] |
