+-------------------------------------------------------------------------------
+-- Agenda View
+-------------------------------------------------------------------------------
+
+function open_agenda()
+ local uv = vim.loop
+ local week_filenames = get_this_weeks_files()
+ local items = {}
+ local pattern = '^%s*%- %[[ ]?x?%]'
+ print(week_filenames[1])
+
+ for _, filename in ipairs(week_filenames) do
+ local daily_note = brain_home .. '/1 periodic/01 journal/' .. filename
+ local stat = uv.fs_stat(daily_note)
+
+ if stat then -- File exists
+ local file, err = io.open(daily_note, 'r')
+ if file then
+ local set_header = 0
+ local line_number = 0
+ for line in file:lines() do
+ line_number = line_number + 1
+ if line:match(pattern) then
+ if set_header == 0 then
+ local header = filename:match('([^/\\]+)$')
+ table.insert(items, {filename = '', lnum = 0, text = header})
+ set_header = 1
+ end
+ table.insert(items, {filename = daily_note, text = line, lnum = line_number})
+ end
+ end
+ file:close()
+ end
+ end
+ end
+ vim.fn.setloclist(0, {}, ' ', {title = 'Weekly Tasks', items = items})
+ vim.cmd('lopen')
+end
+
+-------------------------------------------------------------------------------
+-- Key Bindings
+-------------------------------------------------------------------------------