summaryrefslogtreecommitdiff
path: root/fnl/conf/wictl-nvim/init.fnl
blob: bd0418243d1c4b0e252fe303f58f75a2390587d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(local Path (require :plenary.path))
(tset package.loaded :conf.wict-nvim nil)
(local wict (require :conf.wict-nvim))
(tset package.loaded :conf.wictl-nvim.resolvers nil)
(local Resolver (require :conf.wictl-nvim.resolvers))

(local bld wict.builder)
(local eff wict.effects)

(local config_path (vim.fn.stdpath :config))
(local data_path (vim.fn.stdpath :data))
(local user_config (string.format "%s/wictl.json" config_path))
(local cache_config (string.format "%s/wictl.json" data_path))

(local m {})

(local WictlConfig {})
;; {
;;   ["/path/to/project"] = {
;;      terms = [{cmd = "k9s"}]
;; }

(fn m.Edit [project])

(fn m.Read [path]
  (local p (Path:new path))
  (vim.fn.json_decode (p:read)))

(fn m.Save []
  (local cache-path (Path:new cache_config))
  (cache-path:write (vim.fn.json_encode WictlConfig) :w))

(local ensure-complete-project (fn [config]
                                 (var config (or config {:terms []}))
                                 (if (not config.terms)
                                     (set config.terms
                                          [{:name :k9s :cmd :bash}]))
                                 config))

(local get-project (fn []
                     (local proj (. WictlConfig (Resolver.project_key)))
                     (ensure-complete-project (or proj
                                                  (do
                                                    (local cfg {})
                                                    (tset WictlConfig
                                                          (Resolver.project_key)
                                                          cfg)
                                                    cfg)))))

(fn m.Get-Terms-Config []
  (local proj (get-project))
  proj.terms)

(m.Save)
(m.Read cache_config)
(m.Get-Terms-Config)

m