diff options
Diffstat (limited to '.vim')
| -rw-r--r-- | .vim/lua/internal/job.lua | 60 | ||||
| -rw-r--r-- | .vim/lua/telescope/_extensions/jobs.lua | 15 |
2 files changed, 48 insertions, 27 deletions
diff --git a/.vim/lua/internal/job.lua b/.vim/lua/internal/job.lua index f9f7bf3..c85fd67 100644 --- a/.vim/lua/internal/job.lua +++ b/.vim/lua/internal/job.lua @@ -6,7 +6,8 @@ local M = { } local strip_ansi = function(line) - return line:gsub(string.char(27) .. '[[0-9;]*m', '') + line, _ = line:gsub(string.char(27) .. '[[0-9;]*m', '') + return line end --create a new job and register @@ -24,70 +25,71 @@ function M.jobstart(opts) title = opts.format_title(opts.command, opts.args) opts.format_title = nil else - title = opts.command + title = table.concat({opts.command, unpack(opts.args)}, ' ') end opts.on_start = vim.schedule_wrap(function(j) table.insert(M.current_jobs, j.pid, j) if opts.populate_quickfix then - -- clear quickfix - vim.fn.setqflist({}, 'r') + vim.fn.setqflist({}, 'r') -- clear quickfix end - if opts.enable_spinner then spinner.on_attach(j.pid, title, vim.fn.bufnr()) spinner.on_progress('begin', j.pid, j.pid) end end) - opts.on_exit = vim.schedule_wrap(function(j, _) + opts.on_exit = vim.schedule_wrap(function(j, code) table.remove(M.current_jobs, j.pid) + if not (code == 0) then + vim.notify(string.format('[%d] exit %d', j.pid, code), vim.log.levels.ERROR) + end if opts.populate_quickfix then - vim.cmd([[doautocmd QuickFixCmdPost]]) - -- vim.fn.setqflist({}, 'r', { - -- lines = {}, - -- id = j.pid, - -- }) + vim.cmd.doautocmd [[QuickFixCmdPost]] end - if opts.enable_spinner then spinner.on_progress('end', j.pid, j.pid) spinner.on_exit(nil, nil, j.pid) end end) - opts.on_stdout = vim.schedule_wrap(function(error, data, j) - if error then - vim.notify('error: ' .. error) - return + opts.on_stdout = vim.schedule_wrap(function(err, data, j) + if err ~= nil then + vim.notify(string.format('[%d] error: %s', j.pid, err), vim.log.levels.ERROR) end -- handle error? - if opts.populate_quickfix and data then + if opts.populate_quickfix and data ~= nil then vim.fn.setqflist({}, 'a', { title = title, lines = {strip_ansi(data)}, efm = '%m', - id = j.pid, + context = { + cmd = {opts.command, unpack(opts.args)}, + pid = j.pid, + source = 'jobstart', + } }) end end) - opts.on_stderr = vim.schedule_wrap(function(error, data, j) - if error then - vim.notify('error: ' .. error) - return + opts.on_stderr = vim.schedule_wrap(function(err, data, j) + if err ~= nil then + vim.notify(string.format('[%d] error: %s', j.pid, err), vim.log.levels.ERROR) end -- handle error? - if opts.populate_quickfix and data then + if opts.populate_quickfix and data ~= nil then vim.fn.setqflist({}, 'a', { title = title, lines = {strip_ansi(data)}, efm = '%m', - id = j.pid, + context = { + cmd = {opts.command, unpack(opts.args)}, + pid = j.pid, + source = 'jobstart', + } }) - vim.cmd([[doautocmd QuickFixCmdPost]]) end end) @@ -132,9 +134,15 @@ function M.sh(command_string) -- strip 'sh -c' from the title (used by progress reporting etc.) format_title = function(_, args) - return require('plenary.collections.py_list')(args):slice(2,#args):join(' ') + return table.concat({unpack(args, 2, #args)}, ' ') end } end + +function M.list() + require('telescope').load_extension('jobs') + require('telescope._extensions').manager['jobs']['jobs']() +end + return M diff --git a/.vim/lua/telescope/_extensions/jobs.lua b/.vim/lua/telescope/_extensions/jobs.lua index 8caea2f..ea97ed0 100644 --- a/.vim/lua/telescope/_extensions/jobs.lua +++ b/.vim/lua/telescope/_extensions/jobs.lua @@ -48,8 +48,21 @@ local function list_jobs(opts) actions.select_default:replace(function() local entry = action_state.get_selected_entry() if not entry then return end - entry.value:shutdown(1, 'SIGKILL') actions.close(prompt_bufnr) + vim.ui.select( + {'Terminate', 'Kill', 'Show', 'Cancel'}, + {prompt = 'Select an action:'}, + function(choice) + if choice == 'Cancel' then + return + elseif choice == 'Show' then + vim.fn.getqflist({ id = entry.value.pid }) + elseif choice == 'Kill' then + entry.value.handle:kill('sigkill') + elseif choice == 'Terminate' then + entry.value.handle:kill('sigterm') + end + end) end) return true end, |