Skip to content

Commit 9c8323b

Browse files
author
Waylon S. Walker
committed
add daily_note plugin
1 parent 5e5f06f commit 9c8323b

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
-- Dependencies: os.date, vim.fn, vim.cmd
2+
3+
local M = {}
4+
5+
function M.check_and_open_daily_note()
6+
local daily_dir = "pages/daily"
7+
local today = os.date("%Y-%m-%d")
8+
local pattern = string.format("%s/%s*-notes.md", daily_dir, today)
9+
10+
-- Check if today's note exists
11+
local files = vim.fn.glob(pattern, false, true)
12+
13+
if vim.tbl_isempty(files) then
14+
-- Create new note via copier
15+
os.execute("copier copy ~/.copier-templates/daily .")
16+
17+
-- Re-glob to get the new file (may need to wait a moment for creation)
18+
vim.wait(500, function()
19+
return not vim.tbl_isempty(vim.fn.glob(pattern, false, true))
20+
end, 10)
21+
22+
files = vim.fn.glob(pattern, false, true)
23+
end
24+
25+
-- Open the note (if multiple, just pick the first)
26+
if not vim.tbl_isempty(files) then
27+
vim.cmd("edit " .. files[1])
28+
else
29+
print("Failed to find or create today's note.")
30+
end
31+
vim.cmd("mode")
32+
end
33+
34+
vim.api.nvim_create_user_command("DailyNote", function()
35+
M.check_and_open_daily_note()
36+
end, {})
37+
38+
vim.api.nvim_create_user_command("Daily", function()
39+
M.check_and_open_daily_note()
40+
end, {})
41+
42+
vim.api.nvim_create_user_command("DailyFiles", function()
43+
require("telescope.builtin").find_files({
44+
cwd = "pages/daily",
45+
sorting_strategy = "ascending",
46+
})
47+
end, {})
48+
49+
vim.keymap.set("n", "<leader>dn", M.check_and_open_daily_note)
50+
vim.keymap.set("n", "<leader>df", function()
51+
require("telescope.builtin").find_files({
52+
cwd = "pages/daily",
53+
sorting_strategy = "ascending",
54+
})
55+
end)
56+
57+
return M

nvim/.config/nvim/lua/waylonwalker/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ M.autocmds = require("waylonwalker.autocmds")
2222
M.util = require("waylonwalker.util")
2323
M.plugins = require("waylonwalker.plugins")
2424
M.snippets = require("waylonwalker.snippets")
25+
M.daily_note = require("waylonwalker.daily_note")
2526

2627
return M

0 commit comments

Comments
 (0)