]> git.r.bdr.sh - rbdr/nota.nvim/blame - lua/configuration.lua
Allow next and previous
[rbdr/nota.nvim] / lua / configuration.lua
CommitLineData
503d09fc
RBR
1-------------------------------------------------------------------------------
2-- Configuration for nota
3-------------------------------------------------------------------------------
4local Configuration = {}
5
6local Util = require('util')
7-------------------------------------------------------------------------------
8-- Internal Functions
9-------------------------------------------------------------------------------
10local fs = vim.loop
11
56292c79
RBR
12local 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
503d09fc 36 prefix = '%Y-%m-%d: ' -- Prefix to add when capturing learning entries
56292c79
RBR
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
45local function extend(target, extender)
46 for key, value in pairs(extender) do
503d09fc 47 if type(target[key]) == 'table' and type(value) == 'table' then
56292c79
RBR
48 extend(target[key], value)
49 else
50 target[key] = value
51 end
52 end
53end
54
503d09fc
RBR
55-------------------------------------------------------------------------------
56-- Public Interface
57-------------------------------------------------------------------------------
58
59Configuration.configuration = {}
60extend(Configuration.configuration, defaults)
61
62--- Extends configuration with another configuration
63function Configuration.configure(configuration)
64 configuration = configuration or {}
65 extend(Configuration.configuration, configuration)
66end
67
68--- Gets expanded paths relative to nota_home
69-- @param path string the relative path to expand
70function 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)
75end
76
77--- Loads a template by template name
78function 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
56292c79 88end
503d09fc
RBR
89
90return Configuration