refactor: temp
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
local function run_task(cmd)
|
||||
local buf = vim.api.nvim_create_buf(true, true)
|
||||
vim.api.nvim_buf_set_name(buf, "just://" .. cmd)
|
||||
vim.notify(" Running: " .. cmd)
|
||||
|
||||
vim.api.nvim_buf_call(buf, function()
|
||||
vim.fn.jobstart(cmd, {
|
||||
term = true,
|
||||
on_exit = function(_, code)
|
||||
if code == 0 then
|
||||
vim.notify(" " .. cmd .. " success")
|
||||
vim.schedule(function()
|
||||
pcall(vim.api.nvim_buf_delete, buf, { force = true })
|
||||
end)
|
||||
else
|
||||
vim.notify(" " .. cmd .. " failed (" .. code .. ")", 4)
|
||||
end
|
||||
end,
|
||||
})
|
||||
end)
|
||||
end
|
||||
|
||||
function pick_just_task()
|
||||
local obj = vim.system({ "just", "--summary" }, { text = true }):wait()
|
||||
if obj.code ~= 0 or not obj.stdout or obj.stdout == "" then
|
||||
return vim.notify("No recipes or justfile found", 3)
|
||||
end
|
||||
|
||||
local recipes = vim.split(vim.trim(obj.stdout), "%s+")
|
||||
require("mini.pick").start({
|
||||
source = {
|
||||
items = recipes,
|
||||
name = " Just Tasks",
|
||||
choose = function(choice)
|
||||
run_task("just " .. choice)
|
||||
end,
|
||||
},
|
||||
})
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
local M = {}
|
||||
|
||||
--- Opens a TUI application in a new scratch buffer and deletes the buffer on exit.
|
||||
function M.open_terminal_app(cmd)
|
||||
vim.cmd("enew")
|
||||
vim.fn.termopen(cmd, {
|
||||
on_exit = function()
|
||||
vim.cmd("bdelete!")
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user