diff --git a/lua/helpers.lua b/lua/helpers.lua index 2622561..f63add9 100644 --- a/lua/helpers.lua +++ b/lua/helpers.lua @@ -16,7 +16,7 @@ end helpers.edit_cf('h', '/lua/helpers.lua') ----@param opts? { cmd?: string, win_opts?: table, buf_opts?: table } +---@param opts? { cmd?: string, win_opts?: table, buf_opts?: table, start_insert?: boolean } helpers.open_term = function(opts, buf_opts) opts = opts or {} local cmd = opts.cmd or '' @@ -58,7 +58,35 @@ helpers.open_term = function(opts, buf_opts) end, }) - vim.cmd.startinsert() + if opts.start_insert then + vim.cmd.startinsert() + end +end + +---@param opts? { cmd?: string, win_opts?: table, buf_opts?: table, start_insert?: boolean } +helpers.toggle_term = function(cmd, opts, buf_opts) + local term_bufnr = -1 + for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do + if vim.bo[bufnr].buftype == 'terminal' then + local name = vim.api.nvim_buf_get_name(bufnr) + if name:match(cmd .. '$') then + term_bufnr = bufnr + end + end + end + + if term_bufnr ~= -1 then + vim.api.nvim_open_win(term_bufnr, true) + if opts.start_insert then + vim.cmd.startinsert() + end + return + end + + if not opts.cmd then + opts.cmd = cmd + end + helpers.open_term(opts, buf_opts) end helpers.has_copilot = function() diff --git a/lua/projects/framework_utils/laravel.lua b/lua/projects/framework_utils/laravel.lua index 443ad03..0f5b82d 100644 --- a/lua/projects/framework_utils/laravel.lua +++ b/lua/projects/framework_utils/laravel.lua @@ -116,6 +116,21 @@ end local function laravel_utils(dir) map('D', function() + local term_bufnr = -1 + for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do + if vim.bo[bufnr].buftype == 'terminal' then + local name = vim.api.nvim_buf_get_name(bufnr) + if name:match '/bin/var-dump-server$' then + term_bufnr = bufnr + end + end + end + + if term_bufnr ~= -1 then + vim.api.nvim_open_win(term_bufnr, true) + return + end + helpers.open_term { cmd = dir .. 'vendor/bin/var-dump-server', buf_opts = { diff --git a/lua/projects/runcats.lua b/lua/projects/runcats.lua index cfc3bd7..7d4a336 100644 --- a/lua/projects/runcats.lua +++ b/lua/projects/runcats.lua @@ -26,7 +26,7 @@ return function(dir) vim.api.nvim_create_autocmd({ 'BufWritePre' }, { pattern = { '*.js', '*.ts', '*.vue' }, callback = function(args) - helpers.format_buffer('eslint_d', args.buf) + helpers.format_buffer('eslint_d', args.buf, dir .. '/client/') end, })