all repos

init.lua @ 543dbcd

my nvim config
2 files changed, 47 insertions(+), 0 deletions(-)
feat: add simple per-project note thing
Author: Smirnov Oleksandr ss2316544@gmail.com
Committed at: 2024-05-08 17:41:41 +0300
Parent: 8fd7d62
M lua/core/keymaps.lua

@@ -12,6 +12,12 @@ u.map("n", "Q", "<nop>") -- Q is the worth thing ever

u.map("n", "[b", ":bp<cr>") u.map("n", "]b", ":bn<cr>") u.map("n", "J", "mzJ`z") +u.map("n", "<leader>N", function() + require("scratch.notes").open() +end) +u.map("n", "<leader>n", function() + require("scratch.notes").project() +end) -- quickfix u.map("n", "]q", "<cmd>cnext<cr>")
A lua/scratch/notes.lua

@@ -0,0 +1,41 @@

+local notes = {} + +local config = { + file_extenson = ".md", + data_path = ("%s/ol_notes"):format(vim.fn.stdpath "data"), + open_cmd = "e", +} + +---@return string +---@private +function notes.get_project_path() + return vim.uv.cwd() --[[@as string]] +end + +---@param prj_path string +---@return string +---@private +function notes.get_note_path(prj_path) + if vim.fn.isdirectory(config.data_path) == 0 then + vim.fn.mkdir(config.data_path, "p") + end + + local p = prj_path:gsub("/", "_") + return config.data_path .. "/" .. p .. config.file_extenson +end + +function notes.project() + vim.cmd[config.open_cmd] { + args = { notes.get_note_path(notes.get_project_path()) }, + bang = true, + } +end + +function notes.open() + vim.cmd[config.open_cmd] { + args = { config.data_path .. "/notes.md" }, + bang = true, + } +end + +return notes