From 1bd0e6b464480cf2e7248e66ab80f0f6b0340ecf Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Mon, 9 Sep 2024 04:09:59 +0200 Subject: [PATCH] feat(user_commands): add :Cmake command --- lua/core/user_commands.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lua/core/user_commands.lua b/lua/core/user_commands.lua index 6b6515f..196ef67 100644 --- a/lua/core/user_commands.lua +++ b/lua/core/user_commands.lua @@ -20,3 +20,23 @@ end, { desc = "Update lazy plugins, treesitter parsers and mason language servers", force = false, }) + +vim.api.nvim_create_user_command("Cmake", function(ctx) + local args = ctx.fargs + if vim.tbl_isempty(args) then + args = { "--build", "build" } + end + + local mp = vim.o.makeprg + vim.o.makeprg = "cmake" + local ok, res = pcall(vim.cmd.make, { args = args, bang = ctx.bang }) + vim.o.makeprg = mp + + if not ok then + utils.err(res) + end +end, { + desc = "Like :make, but for CMake", + force = false, + nargs = "*", +})