+local function populate_quicklist_with_files(filenames)
+ local uv = vim.loop
+ local items = {}
+ local pattern = '^%s*%- %[[ ]?x?%]'
+
+ for _, filename in ipairs(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 = string.sub(filename:match('([^/\\]+)$'), 1, -4)
+ 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
+