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..." vim.api.nvim_chan_send(channel, "clear && " .. command .. "; echo '" .. exit_message .. "' && read -s && exit" .. "\n") end local COMMANDS = {} COMMANDS.EditBatConfig = { command = "cmake --build build", description = "Build project" } COMMANDS.SourceCurrentLuaFile = { command = "pwd", description = "Print current working directory" } COMMANDS.AddTempCommand = { command = "echo 'Please implement me! A lua script which is executed maybe? Also remove global variables :p'", description = "TODO IMPLEMENT ME" } 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 executeCommand(listOfCommands) if (string.len(CURRENT_COMMAND) == 0) then selectCommand(listOfCommands, function() executeCommandInTerminal(CURRENT_COMMAND) end) else executeCommandInTerminal(CURRENT_COMMAND) end end vim.keymap.set("n", "mc", function() executeCommand(COMMANDS) end) vim.keymap.set("n", "mC", function() selectCommand(COMMANDS, function() executeCommandInTerminal(CURRENT_COMMAND) end) end)