feat: make helper
This commit is contained in:
parent
07c399dbd8
commit
3fc4739c1b
2 changed files with 42 additions and 1 deletions
|
@ -81,6 +81,24 @@ vim.api.nvim_create_user_command("RetabFile", function ()
|
|||
vim.cmd(":set ts=2 sts=2 noet | retab! | set ts=4 sts=4 et | retab!")
|
||||
end, {})
|
||||
|
||||
local function get_makefile_targets()
|
||||
local makefile = "./Makefile"
|
||||
local targets = {}
|
||||
|
||||
local file = io.open(makefile, "r")
|
||||
if file then
|
||||
for line in file:lines() do
|
||||
local target = line:match("^[^\\s:]+:.*")
|
||||
if target then
|
||||
local tg = target:match("^[^:]+")
|
||||
table.insert(targets, tg)
|
||||
end
|
||||
end
|
||||
file:close()
|
||||
end
|
||||
return targets
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("Make", function (args)
|
||||
local vimCmd = "TermExec cmd=\"make"
|
||||
if (args["args"]) then
|
||||
|
@ -88,4 +106,26 @@ vim.api.nvim_create_user_command("Make", function (args)
|
|||
end
|
||||
vimCmd = vimCmd .. "\""
|
||||
vim.cmd(vimCmd)
|
||||
end, {nargs = "*"})
|
||||
end, {nargs = "*", ["complete"] = function()
|
||||
return get_makefile_targets()
|
||||
end})
|
||||
|
||||
vim.api.nvim_create_user_command("Maket", function()
|
||||
local targets = get_makefile_targets()
|
||||
pickers.new({}, {
|
||||
prompt_title = "Run make target",
|
||||
finder = finders.new_table {
|
||||
results = targets
|
||||
},
|
||||
sorter = conf.generic_sorter({}),
|
||||
attach_mappings = function (prompt_bufnr, map)
|
||||
actions.select_default:replace(function ()
|
||||
actions.close(prompt_bufnr)
|
||||
local selection = action_state.get_selected_entry()
|
||||
selection = selection[1]
|
||||
vim.cmd(":Make " .. selection)
|
||||
end)
|
||||
return true
|
||||
end
|
||||
}):find()
|
||||
end, {})
|
||||
|
|
|
@ -57,6 +57,7 @@ local keys = {
|
|||
b = {require("telescope.builtin").buffers, "buffers"},
|
||||
h = {require("telescope.builtin").help_tags, "help tags"},
|
||||
s = {function () require("telescope.builtin").grep_string({ search = vim.fn.input("Grep > ")}); end, "grep search through files"},
|
||||
m = {"<cmd>Maket<cr>", "Make"},
|
||||
},
|
||||
s = {
|
||||
name = "Settings",
|
||||
|
|
Loading…
Reference in a new issue