dots - my configuration files
notes.lua (3959B) - raw
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | local notes_dir = vim.fn.expand("$HOME/notes") local work_notes_dir = vim.fn.expand("$HOME/notes/work") vim.api.nvim_create_autocmd({ "bufenter", "bufleave" }, { pattern = { notes_dir .. "/**/*.md" }, command = "setl noswapfile noundofile nobackup viminfo=", }) --[[ require("mkdnflow").setup({ perspective = { priority = "current", }, links = { transform_explicit = function(text) text = text:gsub(" ", "-") text = text:lower() return text end, }, }) ]] -- create daily journal entry command local function daily_file(directory) local date_string = os.date("%Y-%m-%d") local dir = vim.fn.expand(directory .. "/daily/") return dir .. date_string .. ".md" end local function create_or_open_file(directory, template_path) local file_path = daily_file(directory) local f = io.open(file_path, "r") if f ~= nil then f:close() else local dir = vim.fn.expand(directory .. "/daily/") local template = io.open(dir .. template_path, "r") if template == nil then vim.cmd("echo 'no daily template found in " .. dir .. "'") return end local template_content = template:read("*all") template:close() local new_file = io.open(file_path, "w") if new_file ~= nil then new_file:write("# " .. os.date("%Y-%m-%d") .. "\n\n") new_file:write(template_content) new_file:close() end end vim.cmd("edit " .. file_path) end -- create daily journal entry command vim.api.nvim_create_user_command("Today", function() create_or_open_file(notes_dir, "template.md") end, {}) vim.api.nvim_create_user_command("Yesterday", function() local date_string = os.date("%Y-%m-%d", os.time() - 86400) local file_path = vim.fn.expand(notes_dir .. "/daily/" .. date_string .. ".md") if vim.fn.filereadable(file_path) == 1 then vim.cmd("edit " .. file_path) else vim.cmd("echo 'no daily entry for " .. date_string .. "'") end end, {}) vim.api.nvim_create_user_command("WorkToday", function() create_or_open_file(work_notes_dir, "template.md") end, {}) vim.api.nvim_create_user_command("WorkYesterday", function() local date_string = os.date("%Y-%m-%d", os.time() - 86400) local file_path = vim.fn.expand(work_notes_dir .. "/daily/" .. date_string .. ".md") if vim.fn.filereadable(file_path) == 1 then vim.cmd("edit " .. file_path) else vim.cmd("echo 'no daily entry for " .. date_string .. "'") end end, {}) function Daily_status(directory) if vim.fn.filereadable(daily_file(directory)) == 1 then return "" else return "pending" end end -- function to get file path for tomorrow's file local function tomorrow_file(directory, template_path) local date_string = os.date("%Y-%m-%d", os.time() + 86400) local dir = vim.fn.expand(directory .. "/daily/") return dir .. date_string .. ".md" end -- create or open file for tomorrow's entry local function create_or_open_tomorrow_file(directory, template_path) local file_path = tomorrow_file(directory, template_path) local f = io.open(file_path, "r") if f ~= nil then f:close() else local dir = vim.fn.expand(directory .. "/daily/") local template = io.open(dir .. template_path, "r") if template == nil then vim.cmd("echo 'no daily template found in " .. dir .. "'") return end local template_content = template:read("*all") template:close() local new_file = io.open(file_path, "w") if new_file then new_file:write("# " .. os.date("%Y-%m-%d", os.time() + 86400) .. "\n\n") new_file:write(template_content) new_file:close() end end vim.cmd("edit " .. file_path) end -- create WorkTomorrow command vim.api.nvim_create_user_command("WorkTomorrow", function() create_or_open_tomorrow_file(work_notes_dir, "template.md") end, {}) vim.api.nvim_create_user_command("QuickNote", function(opts) local note = opts.args or nil local file_path = vim.fn.expand(notes_dir .. "/quick-notes.md") local f = io.open(file_path, "a") if f ~= nil then f:write("\n\n" .. note .. "\n\n") f:close() end end, { nargs = "?" }) |