summaryrefslogtreecommitdiff
path: root/.config/nvim/lua
diff options
context:
space:
mode:
authorKyren223 <contact@kyren.codes>2026-06-01 17:26:22 +0300
committerKyren223 <contact@kyren.codes>2026-06-01 17:26:22 +0300
commitd72fa0690ac8df78fddd39156e8da4da6f6040c6 (patch)
tree774ae3974b789d859fd43ab11ddfdc2c2e8ce6b4 /.config/nvim/lua
parentdf5a87965ea0004e5c46bacd2b458002ce8cbe18 (diff)
add support for memories to keep track of stuff like installing lua
Diffstat (limited to '.config/nvim/lua')
-rw-r--r--.config/nvim/lua/extra.lua64
-rw-r--r--.config/nvim/lua/keymaps.lua4
2 files changed, 67 insertions, 1 deletions
diff --git a/.config/nvim/lua/extra.lua b/.config/nvim/lua/extra.lua
index ddf65ce..a5c2916 100644
--- a/.config/nvim/lua/extra.lua
+++ b/.config/nvim/lua/extra.lua
@@ -674,5 +674,69 @@ vim.api.nvim_create_autocmd({ 'VimEnter', 'BufWritePost' }, {
})
----------------------------------------------------------------------------
+-- NOTE: utility to create a new "k memory"
+----------------------------------------------------------------------------
+local function create_and_or_open_memory()
+ vim.ui.input({ prompt = 'Enter title: ' }, function(title)
+ if not title or title == '' then
+ return
+ end
+
+ local sanitized_title = title:gsub('%s+', '-')
+ local cmd = { 'k', 'memory', sanitized_title, '--output-path', '--edit=false', '--no-rebuild-self' }
+ local output_lines = {}
+ vim.notify('Memory command: ' .. vim.inspect(cmd))
+
+ vim.fn.jobstart(cmd, {
+ stdout_buffered = true,
+ stderr_buffered = true,
+
+ on_stdout = function(_, data)
+ if data then
+ for _, line in ipairs(data) do
+ if line ~= '' then
+ table.insert(output_lines, line)
+ end
+ end
+ end
+ end,
+
+ on_stderr = function(_, data)
+ if data then
+ for _, line in ipairs(data) do
+ if line ~= '' then
+ table.insert(output_lines, line)
+ end
+ end
+ end
+ end,
+
+ on_exit = function(_, exit_code)
+ if exit_code == 0 then
+ local target_file = output_lines[#output_lines]
+ vim.notify(vim.inspect(output_lines))
+
+ if target_file and target_file ~= '' then
+ -- Trim any trailing carriage returns or spaces
+ target_file = target_file:gsub('%s+$', '')
+
+ vim.schedule(function()
+ vim.cmd('edit ' .. vim.fn.fnameescape(target_file))
+ end)
+ else
+ vim.notify('Error: CLI succeeded but stdout was empty!', vim.log.levels.ERROR)
+ end
+ else
+ vim.api.nvim_err_writeln("Error: 'k memory' failed with exit code " .. exit_code)
+ end
+ end,
+ })
+ end)
+end
+
+-- 5. Create the Neovim user command (:MyCliCreate)
+vim.api.nvim_create_user_command('KMemory', create_and_or_open_memory, {})
+
+----------------------------------------------------------------------------
-- NOTE:
----------------------------------------------------------------------------
diff --git a/.config/nvim/lua/keymaps.lua b/.config/nvim/lua/keymaps.lua
index f05ffc3..0c25603 100644
--- a/.config/nvim/lua/keymaps.lua
+++ b/.config/nvim/lua/keymaps.lua
@@ -183,5 +183,7 @@ vim.keymap.set('n', '<A-t>', test, { desc = '[T]est Project' })
vim.keymap.set('n', '<A-s>', function()
Run_nvim_lua()
- vim.notify("Reloaded .nvim.lua")
+ vim.notify('Reloaded .nvim.lua')
end, { desc = '[S]ource .nvim.lua' })
+
+vim.keymap.set('n', '<leader>cm', '<cmd>KMemory<cr>', { desc = '[C]reate [M]emory' })