Utility to intelligently calculate likely makeprg targets to easily select a
build target.
Detects files such as Makefile and CMakeLists.txt and builds up options
that you may want to use as the vim makeprg, and supports a vim ui prompt for
you to choose one.
This allows easily building the application with :make, or m<CR> to
dispatch a background build when using
tpope/vim-dispatch.
:BuildSelector
Or add a key-map such as
vim.keymap.set('n', '<leader>b', require('build-selector').choose_default)This pops up the default ui-select menu with selections, e.g.
1. make -f Makefile
2. cmake --build build-debug --parallel
3. cmake --build build-rpi-release --parallel
4. odin build mylibOr if using something like telescope-ui-select:

Detects Makefile and makefile, and adds options make -f <FILE>
Detects CMakeLists.txt and then searches for build*/CMakeCache.txt and adds
cmake --build <PATH> --parallel for each of them.
Detects *.odin and then adds odin build <dir> for each unique directory.
Detects *.jai and then adds jai -x64 <file> for each file, prioritising
first*.jai and build*.jai
Detects .devcontainer.json, .devcontainer/devcontainer.json,
.devcontainer/*/devcontainer/json (depth one) to find devcontainers.
Each devcontainer duplicates previous entries with
docker exec <NAME> <COMMAND> where NAME is the devcontainer name, and
COMMAND is one of the earlier detected makeprg options. For example,
docker exec MyContainerName cmake --build build-gcc-debug --parallel
Using Lazy.nvim:
{
"segcore/build-selector.nvim",
dependencies = {
"nvim-lua/plenary.nvim", -- Optional; to simplify file paths
},
opts = {},
}Available options, documented with their default values:
opts = {
simplify = true, -- Simplify file paths relative to the current working directory
add_command = true, -- Add the :BuildSelector user command
selected_callback = function(item) vim.opt.makeprg = item end, -- Called when an item is selected
makefile = true, -- Look for Makefiles
cmake = true, -- Look for CMake build directories
odin = true, -- Look for Odin directories
jai = true, -- Look for Jai files
devcontainer = true, -- Look for devcontainer files
ui_select_kind = nil, -- 'kind' to pass to vim.ui.select()
}A more extravagant example:
{
"segcore/build-selector.nvim",
config = function()
local bs = require('build-selector')
bs.setup({ simplify = false })
vim.keymap.set('n', '<leader>b', bs.choose_default, { desc = 'Open build selector' })
vim.keymap.set('n', '<leader>B', function()
local choices = bs.choices()
choices = vim.tbl_filter(function(entry)
return string.match(entry, "docker")
end, choices)
bs.choose(choices)
end, { desc = 'Open build selector for docker builds' })
end,
},