diff options
| author | Robert Günzler <r@gnzler.io> | 2026-02-10 12:32:48 +0100 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2026-02-10 12:41:25 +0100 |
| commit | 63feeb9f369fc6176e85c1c2d8fcc863caad1946 (patch) | |
| tree | 41cd5d2d1ec36e74e464caab722cc9b460153f04 /.vim/plugin/termopen.lua | |
| parent | 5bd0a4aca65ecb9818ef1285982d160b6b6ff665 (diff) | |
start new
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '.vim/plugin/termopen.lua')
| -rw-r--r-- | .vim/plugin/termopen.lua | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/.vim/plugin/termopen.lua b/.vim/plugin/termopen.lua deleted file mode 100644 index 951857f..0000000 --- a/.vim/plugin/termopen.lua +++ /dev/null @@ -1,72 +0,0 @@ -local function termopen(opts) - opts = opts or {} - - -- setup the buffer - local buf = vim.api.nvim_create_buf(false, true) - vim.api.nvim_set_option_value('bufhidden', 'wipe', { buf = buf }) - vim.api.nvim_set_option_value('modifiable', false, { buf = buf }) - - -- setup keymappings - vim.keymap.set('n', 'q', '<cmd>close<cr>', { buffer = buf }) - vim.keymap.set('n', '<esc>', '<cmd>close<cr>', { buffer = buf }) - - -- setup the window - local w = math.ceil(vim.o.columns * 1.0) - local h = math.ceil(vim.o.lines * 0.4) - local win = vim.api.nvim_open_win(buf, true, { - style = 'minimal', - relative = 'editor', - width = w, - height = h, - row = math.ceil(vim.o.lines - h), - col = vim.o.columns, - border = { ' ', '─', ' ', ' ', ' ', '─', ' ', ' ' }, - }) - 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 - end, - }) - - -- put into insert mode - vim.cmd.startinsert() -end - --- provide user commands -vim.api.nvim_create_user_command('Termopen', function(a) - termopen({ cmd = a.fargs }) -end, { nargs = '*' }) - --- alias -vim.api.nvim_create_user_command('T', function(a) - termopen({ cmd = a.fargs }) -end, { nargs = '*' }) - --- helper to spawn &makeprg -vim.api.nvim_create_user_command('Make', function(a) - 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) - return p - 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' }) |