summaryrefslogtreecommitdiff
path: root/lua/aotrix/build.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/aotrix/build.lua')
-rw-r--r--lua/aotrix/build.lua48
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)