chore(vim): add taskfile plugin
This commit is contained in:
parent
23b34a3260
commit
f205f1b2bf
2 changed files with 51 additions and 0 deletions
|
|
@ -70,6 +70,15 @@ noremap <leader>; gcc
|
|||
inoremap jj <esc>:w<cr>
|
||||
nnoremap <leader><tab> <c-^>
|
||||
|
||||
|
||||
" Add mapping to "Run" tasks from the taskfile
|
||||
"
|
||||
" This needs to be added here so its defined before the Ferret plugin is
|
||||
" loaded. Ferret adds a mapping to <leader>r only if one is not defined. If we
|
||||
" do this in the taksfile plugin it will be too late and the Ferret mapping
|
||||
" will only be added.
|
||||
nmap <silent> <Leader>r :IvyTaskfile<cr>
|
||||
|
||||
" Use the CommandTWildIgnore insted of the wildignore so I can still get
|
||||
" completion for :e in folders like vendor or node_modules but, they will be
|
||||
" ignored from command-t file searches.
|
||||
|
|
|
|||
42
site-modules/core/files/vim/plugin/taskfile.lua
Normal file
42
site-modules/core/files/vim/plugin/taskfile.lua
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
local libivy = require "ivy.libivy"
|
||||
|
||||
local get_tasks = function()
|
||||
local task_output, _ = vim.fn.system { "task", "-j", "--list" }
|
||||
local output = vim.json.decode(task_output)
|
||||
|
||||
return output.tasks
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("IvyTaskfile", function()
|
||||
local task_list = get_tasks()
|
||||
vim.ivy.run("Taskfile", function(input)
|
||||
local tasks = {}
|
||||
for _, task in ipairs(task_list) do
|
||||
local content = task.name .. " » " .. task.desc
|
||||
local score = libivy.ivy_match(input, content)
|
||||
if score > -200 then
|
||||
table.insert(tasks, { content = content, score = score })
|
||||
end
|
||||
end
|
||||
|
||||
table.sort(tasks, function(a, b)
|
||||
return a.score < b.score
|
||||
end)
|
||||
|
||||
return tasks
|
||||
end, function(item)
|
||||
local name, _ = unpack(vim.split(item, " » "))
|
||||
vim.fn.jobstart({ "task", name }, {
|
||||
on_stdout = function(_, data)
|
||||
print(table.concat(data, "\n"))
|
||||
end,
|
||||
on_exit = function(_, data)
|
||||
if data ~= 0 then
|
||||
print("Task " .. name .. " failed")
|
||||
else
|
||||
print("Task " .. name .. " succeeded")
|
||||
end
|
||||
end,
|
||||
})
|
||||
end)
|
||||
end, {})
|
||||
Loading…
Reference in a new issue