summary refs log tree commit diff
path: root/.vim/lua/telescope/_extensions/jobs.lua
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2023-01-19 18:33:43 +0100
committerRobert Günzler <r@gnzler.io>2023-01-19 18:33:43 +0100
commitfc67eecc8a40bf28d3d2b190702e58c580bfba9f (patch)
tree0b8d0455046ae484e036d2f9dfa69306bbea811d /.vim/lua/telescope/_extensions/jobs.lua
parentc03b74ce367d6e9e2988dbb4a18985bc372dd8a6 (diff)
vim: format config with stylua
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '.vim/lua/telescope/_extensions/jobs.lua')
-rw-r--r--.vim/lua/telescope/_extensions/jobs.lua76
1 files changed, 42 insertions, 34 deletions
diff --git a/.vim/lua/telescope/_extensions/jobs.lua b/.vim/lua/telescope/_extensions/jobs.lua
index ea97ed0..be55a47 100644
--- a/.vim/lua/telescope/_extensions/jobs.lua
+++ b/.vim/lua/telescope/_extensions/jobs.lua
@@ -1,4 +1,4 @@
-local job = require('job')
+local job = require('internal.job')
 
 local pickers = require('telescope.pickers')
 local finders = require('telescope.finders')
@@ -10,7 +10,7 @@ local entry_display = require('telescope.pickers.entry_display')
 local function job_entry_maker(_)
   return function(j)
     local displayer = entry_display.create({
-      separator = " ",
+      separator = ' ',
       items = {
         { width = 8 },
         { remaining = true },
@@ -18,7 +18,7 @@ local function job_entry_maker(_)
     })
     local make_display = function(e)
       return displayer({
-        { e.value.pid, "TelescopeResultsNumber" },
+        { e.value.pid, 'TelescopeResultsNumber' },
         (e.value.command .. ' ' .. table.concat(e.value.args, ' ')),
       })
     end
@@ -35,42 +35,50 @@ local function list_jobs(opts)
   for _, j in pairs(job.current_jobs) do
     table.insert(jobs, j)
   end
-  if #jobs == 0 then return end
+  if #jobs == 0 then
+    vim.notify('no jobs')
+    return
+  end
 
-  opts = vim.tbl_extend("force", { prompt_title = 'Jobs' }, opts or {})
-  pickers.new(opts, {
-    finder = finders.new_table {
-      results = jobs,
-      entry_maker = job_entry_maker(opts),
-    },
-    sorter = conf.generic_sorter(opts),
-    attach_mappings = function(prompt_bufnr, _)
-      actions.select_default:replace(function()
-        local entry = action_state.get_selected_entry()
-        if not entry then return end
-        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')
+  opts = vim.tbl_extend('force', { prompt_title = 'Jobs' }, opts or {})
+  pickers
+    .new(opts, {
+      finder = finders.new_table({
+        results = jobs,
+        entry_maker = job_entry_maker(opts),
+      }),
+      sorter = conf.generic_sorter(opts),
+      attach_mappings = function(prompt_bufnr, _)
+        actions.select_default:replace(function()
+          local entry = action_state.get_selected_entry()
+          if not entry then
+            return
+          end
+          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)
-      end)
-      return true
-    end,
-  }):find()
+          )
+        end)
+        return true
+      end,
+    })
+    :find()
 end
 
 return require('telescope').register_extension({
   exports = {
     jobs = list_jobs,
-  }
+  },
 })