diff options
Diffstat (limited to '')
| -rw-r--r-- | .vim/plugin/termopen.lua | 21 |
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' }) |