about summary refs log tree commit diff
path: root/lua/sketchbook/create_note.lua
blob: 7bd2815ceefe49ac27f6c2659aa6a0b1d58f6c95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
local M = {}

function M.create_new_note()
	local notes_dir = vim.g.notes_directory or "~/notes/"
	local filename = os.date("%Y-%m-%d_%H-%M-%S") .. ".md"
	local filepath = vim.fn.expand(notes_dir) .. filename
	local title = "Title " .. os.date("%Y-%m-%d %H:%M:%S")
	local template = {
		"# " .. title,
		"",
	}
	local file = io.open(filepath, "w")
	for _, line in ipairs(template) do
		file:write(line .. "\n")
	end
	file:close()
	vim.cmd("edit " .. filepath)
end

return M