From c048e460d406de1374eebd37052494fd54a33468 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 10 Nov 2024 23:54:10 +0100 Subject: [PATCH] Better note creation and such --- lua/plugins/telescope.lua | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index 9ffbf96..c3ef163 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -90,7 +90,7 @@ return { -- Fuzzy Finder (files, lsp, etc) end, { desc = '[/] Fuzzily search in current buffer' }) -- Vimwiki searches for notes in path specified by $NOTES environment variable - vim.keymap.set('n', 'sv', function() + vim.keymap.set('n', 'svv', function() local notes_path = os.getenv 'NOTES' if not notes_path then error 'Please set the $NOTES environment variable' @@ -99,6 +99,36 @@ return { -- Fuzzy Finder (files, lsp, etc) end end, { desc = '[S]earch [V]imWiki' }) + vim.keymap.set('n', 'svn', function() + local notes_path = os.getenv 'NOTES' + if not notes_path then + error 'Please set the $NOTES environment variable' + return + end + + local function prompt_for_filename() + local filename = vim.fn.input 'Enter note filename: ' + if filename == '' then + error 'Filename cannot be empty' + end + return filename + end + + local function open_or_create_note() + local filename = prompt_for_filename() + local file_path = notes_path .. '/' .. filename .. '.md' + if vim.fn.filereadable(file_path) == 0 then + vim.cmd('edit ' .. file_path) + print('Created new note: ' .. file_path) + else + vim.cmd('edit ' .. file_path) + print('Opened existing note: ' .. file_path) + end + end + + open_or_create_note() + end, { desc = '[S]earch or [V]iew/Create Note' }) + -- It's also possible to pass additional configuration options. -- See `:help telescope.builtin.live_grep()` for information about particular keys vim.keymap.set('n', 's/', function()