]> git.r.bdr.sh - rbdr/nota.nvim/blob - lua/nota/configuration.lua
Namespace the plugin
[rbdr/nota.nvim] / lua / nota / configuration.lua
1 -------------------------------------------------------------------------------
2 -- Configuration for nota
3 -------------------------------------------------------------------------------
4 local Configuration = {}
5
6 local Util = require('nota.util')
7 -------------------------------------------------------------------------------
8 -- Internal Functions
9 -------------------------------------------------------------------------------
10 local fs = vim.loop
11
12 local defaults = {
13 nota_home = '~/.local/share/nota', -- Root location in which to store all notes
14 default_keybinds = true, -- Whether or not to set the default keybinds
15 periodic_locations = {
16 daily = 'periodic/daily', -- Location to store daily notes, relative to nota_home
17 weekly = 'periodic/weekly', -- Location to store weekly notes, relative to nota_home
18 monthly = 'periodic/monthly', -- Location to store monthly notes, relative to nota_home
19 seasonal = 'periodic/seasonal', -- Location to store seasonal notes, relative to nota_home
20 yearly = 'periodic/yearly' -- Location to store yearly notes, relative to nota_home
21 },
22 templates = {
23 daily = 'templates/daily.md', -- Template for daily notes, relative to nota_home
24 weekly = 'templates/weekly.md', -- Template for weekly notes, relative to nota_home
25 monthly = 'templates/monthly.md', -- Template for monthly notes, relative to nota_home
26 seasonal = 'templates/seasonal.md', -- Template for seasonal notes, relative to nota_home
27 yearly = 'templates/yearly.md', -- Template for yearly notes, relative to nota_home
28 plan = 'templates/plan.md' -- Template for plan notes, relative to nota_home
29 },
30 tasks = {
31 inbox = 'inbox.md', -- Location of the file in which to store newly captured tasks, relative to nota_home
32 someday = 'someday.md' -- Location of the file in which to store indefinitely deferred tasks, relative to nota_home
33 },
34 learning = {
35 learning_file = 'learning.md', -- Location of the file in which to store learning entries, relative to nota_home
36 prefix = '%Y-%m-%d: ' -- Prefix to add when capturing learning entries
37 },
38 plan = {
39 archive = 'plans', -- Location of the plan archives.
40 plan_file = '~/.plan' -- Location of the active plan, the default is what is expected by finger.
41 }
42 }
43
44 -- Recursively extends a table with another
45 local function extend(target, extender)
46 for key, value in pairs(extender) do
47 if type(target[key]) == 'table' and type(value) == 'table' then
48 extend(target[key], value)
49 else
50 target[key] = value
51 end
52 end
53 end
54
55 -------------------------------------------------------------------------------
56 -- Public Interface
57 -------------------------------------------------------------------------------
58
59 Configuration.configuration = {}
60 extend(Configuration.configuration, defaults)
61
62 --- Extends configuration with another configuration
63 function Configuration.configure(configuration)
64 configuration = configuration or {}
65 extend(Configuration.configuration, configuration)
66 end
67
68 --- Gets expanded paths relative to nota_home
69 -- @param path string the relative path to expand
70 function Configuration.path_for(path)
71 if not path then
72 return vim.fn.expand(Configuration.configuration.nota_home)
73 end
74 return Util.join(vim.fn.expand(Configuration.configuration.nota_home), path)
75 end
76
77 --- Loads a template by template name
78 function Configuration.load_template(type)
79 local template_path = Configuration.path_for(Configuration.configuration.templates[type])
80
81 local template_file = io.open(template_path, 'r')
82 if not template_file then
83 return ''
84 end
85 local content = template_file:read('*a')
86 template_file:close()
87 return content
88 end
89
90 return Configuration