build allows you to run your build commands from neovim like with default make.
WIP: Add here gif usage example
To start using build plugin use command :Build generate and in newely created build file add your configuration. In conf object use keys as commands' names and values as commands to run:
---@param cmd string
---@return string
local function runTestsCommand(cmd)
local runner = "./run_tests.sh \"%s\""
return string.format(runner, cmd)
end
---@return string
local function getCurrentFileName()
local filePath = vim.fn.expand("%")
local pathComponents = vim.fn.split(filePath, "/")
local file = pathComponents[#pathComponents]
local fileName = vim.fn.split(file, "%.")
return fileName[#fileName]
end
conf = {
install = "sudo luarocks make",
remove = "sudo luarocks remove cluautils",
currentTest = runTestsCommand(getCurrentFileName()),
allTest = runTestsCommand("*"),
threadTest = [[
bear -- make build
make test_thread
]] .. runTestsCommand("cthread*"),
memoryTest = [[
bear -- make build
]] .. runTestsCommand("cmemory*"),
oopTest = runTestsCommand("oop"),
stringTest = runTestsCommand("string_utils*"),
jsonTest = runTestsCommand("json*"),
fmTest = runTestsCommand("file_manager*"),
tableTest = runTestsCommand("table_utils*"),
hashmapTest = runTestsCommand("*hashmap*"),
linkedlistTest = runTestsCommand("linkedlist*"),
}As you can see, your commands can return either string representation of terminal command or a function to run! Strings will run in toggleterm while functions will just run.
After saving build file you can use all your declared commands like this: :Build <your_command_name>.
You can edit your configuration file with :Build edit command.
Prerequisites:
-
cluautilslibrary. Library with different lua tools.Can be installed with
luarocks:luarocks install cluautils -
akinsho/toggletermplugin. Manages running commands.
Install plugin with your favourite plugin manager like this:
require("lazy").setup {
{ "castlele/build.nvim" },
}To enable plugin you have to run setup method:
require("build").setup()With no arguments provided build plugin will use default settings:
require("build").setup {
buildFileName = "build.lua",
telescope = {
enabled = pcall(require, "telescope"),
keymap = "<leader>B",
},
}By default if you have a telescope plugin installed you will be able to navigate over your builds with telescope search. Default key combination is <leader>B, but you can change it with:
require("build").setup {
telescope = {
keymap = "your key combination here",
},
}