summary refs log tree commit diff
path: root/.vim/plugin/termopen.lua
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2025-04-30 13:14:22 +0200
committerRobert Günzler <r@gnzler.io>2025-04-30 13:14:22 +0200
commit6a1810f4dfe4ac22dfbaf2b98fb7618fd76eb761 (patch)
treed9cc1046e3305476e2eea284fbdafde049cf3e10 /.vim/plugin/termopen.lua
parent59bdb9bc3f7b06b886a24def842f62f350f1411b (diff)
vim: misc updates
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '')
-rw-r--r--.vim/plugin/termopen.lua21
1 files changed, 17 insertions, 4 deletions
diff --git a/.vim/plugin/termopen.lua b/.vim/plugin/termopen.lua
index 68b9d8d..951857f 100644
--- a/.vim/plugin/termopen.lua
+++ b/.vim/plugin/termopen.lua
@@ -25,11 +25,14 @@ local function termopen(opts)
   vim.api.nvim_set_current_win(win)
 
   -- spawn the command
+  if #opts.cmd == 0 then
+    opts.cmd = { vim.env.SHELL }
+  end
   vim.fn.termopen(opts.cmd, {
     on_exit = function()
-      if vim.api.nvim_win_is_valid(win) then
-        vim.api.nvim_win_close(win, true)
-      end
+      -- if vim.api.nvim_win_is_valid(win) then
+      --   vim.api.nvim_win_close(win, true)
+      -- end
     end,
   })
 
@@ -49,7 +52,13 @@ end, { nargs = '*' })
 
 -- helper to spawn &makeprg
 vim.api.nvim_create_user_command('Make', function(a)
-  local cmd = vim.split(vim.o.makeprg, ' ')
+  if vim.opt_local.makeprg == nil then
+    vim.ui.input({ prompt = 'Enter makeprg: ' }, function(input)
+      vim.opt_local.makeprg = input
+    end)
+  end
+
+  local cmd = vim.split(vim.opt_local.makeprg:get(), ' ')
   cmd = vim.tbl_map(function(p)
     p, _ = string.gsub(p, [[%$%*]], a.args)
     p, _ = vim.fn.expand(p)
@@ -57,3 +66,7 @@ vim.api.nvim_create_user_command('Make', function(a)
   end, cmd)
   termopen({ cmd = cmd })
 end, { nargs = '*' })
+
+-- setup keymappings
+vim.keymap.set('n', '<leader><leader>m', '<cmd>Make<cr>', { desc = 'Run :Make' })
+vim.keymap.set('n', '<leader><leader>t', '<cmd>Termopen<cr>', { desc = 'Run :Termopen' })