diff options
| author | Aotrix <[email protected]> | 2026-05-31 20:50:01 +0200 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2026-05-31 20:50:01 +0200 |
| commit | 4ad83cd3c96f733f41cbb28d09b1894994bac7d8 (patch) | |
| tree | 7fee4afe0a99dffd912580cde73e64f2feb76a33 /lua/aotrix/build.lua | |
| parent | 0c7194e485664bea2702fb5cde473a29c632a8e3 (diff) | |
Add list of commands for projects
Diffstat (limited to 'lua/aotrix/build.lua')
| -rw-r--r-- | lua/aotrix/build.lua | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/lua/aotrix/build.lua b/lua/aotrix/build.lua index 843d950..94d49b1 100644 --- a/lua/aotrix/build.lua +++ b/lua/aotrix/build.lua @@ -1,8 +1,10 @@ -local BUILD_COMMAND = "" +local CURRENT_COMMAND = "" ---@param command string ---@return nil function executeCommandInTerminal(command) + vim.cmd.term() + vim.cmd.startinsert() local channel = vim.bo.channel -- 'clear' is used to hide the command local exit_message = "\nPress enter to exit..." @@ -11,18 +13,42 @@ function executeCommandInTerminal(command) "' && read -s && exit" .. "\n") end -function setBuildCommand() - BUILD_COMMAND = vim.fn.input("Enter compile command: ", BUILD_COMMAND) +local COMMANDS = {} +COMMANDS.EditBatConfig = { + command = "cmake --build build", + description = "Build project" +} + +COMMANDS.SourceCurrentLuaFile = { + command = "pwd", + description = "Print current working directory" +} + +function selectCommand(listOfCommands, callback) + vim.ui.select(vim.tbl_keys(listOfCommands), { + prompt = "Select your command.", + format_item = function(item) + return listOfCommands[item].description + end + }, function(choice) + if (choice ~= nil) then + CURRENT_COMMAND = listOfCommands[choice].command + callback() + end + end) end -function build() - if string.len(BUILD_COMMAND) == 0 then setBuildCommand() end - if string.len(BUILD_COMMAND) > 0 then - vim.cmd.term() - vim.cmd.startinsert() - executeCommandInTerminal(BUILD_COMMAND) +function executeCommand(listOfCommands) + if (string.len(CURRENT_COMMAND) == 0) then + selectCommand(listOfCommands, + function() + executeCommandInTerminal(CURRENT_COMMAND) + end) end end -vim.keymap.set("n", "mC", setBuildCommand) -vim.keymap.set("n", "mc", build) +vim.keymap.set("n", "mc", function() executeCommand(COMMANDS) end) +vim.keymap.set("n", "mC", function() + selectCommand(COMMANDS, + function() executeCommandInTerminal(CURRENT_COMMAND) end) +end) |
