Compare commits

...

2 commits

Author SHA1 Message Date
Imbus
c048e460d4 Better note creation and such 2024-11-10 23:54:10 +01:00
Imbus
3555e9dc0a CD to git root user cmd 2024-11-10 23:53:36 +01:00
2 changed files with 44 additions and 1 deletions

View file

@ -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

View file

@ -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', '<leader>sv', function()
vim.keymap.set('n', '<leader>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', '<leader>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', '<leader>s/', function()