From 3555e9dc0afc349fb9061117703ef59dc77a538d Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 10 Nov 2024 23:53:36 +0100 Subject: [PATCH 1/2] CD to git root user cmd --- lua/autocmd.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lua/autocmd.lua b/lua/autocmd.lua index ef6d522..58256e3 100644 --- a/lua/autocmd.lua +++ b/lua/autocmd.lua @@ -25,4 +25,17 @@ vim.api.nvim_create_autocmd('TextYankPost', { end, }) +vim.api.nvim_create_user_command('CDToGitRoot', function() + local handle = io.popen 'git rev-parse --show-toplevel 2>/dev/null' + local git_root = handle:read('*a'):gsub('\n', '') + handle:close() + + if git_root == '' then + print 'Not in a Git repository' + else + vim.cmd('cd ' .. git_root) + print('Changed directory to Git root: ' .. git_root) + end +end, { desc = 'Change directory to the current Git repository root' }) + -- vim: ts=2 sts=2 sw=2 et From c048e460d406de1374eebd37052494fd54a33468 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 10 Nov 2024 23:54:10 +0100 Subject: [PATCH 2/2] 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()