diff options
| author | Aotrix <[email protected]> | 2026-06-03 21:02:19 +0200 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2026-06-03 21:02:19 +0200 |
| commit | 1f0ab79a26a3bfc396f8fa09a1acda0df2d2fec3 (patch) | |
| tree | e9de139009b6797da4d3fe507c19828a96688dc8 | |
| parent | 9a6d1d677283ce759d0317efffa0451d57737ffe (diff) | |
Create temporary command
| -rw-r--r-- | lua/aotrix/build.lua | 27 | ||||
| -rw-r--r-- | lua/aotrix/personal_commands.lua | 8 |
2 files changed, 20 insertions, 15 deletions
diff --git a/lua/aotrix/build.lua b/lua/aotrix/build.lua index c429467..35d9675 100644 --- a/lua/aotrix/build.lua +++ b/lua/aotrix/build.lua @@ -1,16 +1,19 @@ -local CURRENT_COMMAND = "" +local CURRENT_COMMAND = nil ----@param command string +---@param command string|nil ---@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") + if (command ~= nil) then + vim.cmd.term() + vim.cmd.startinsert() + local channel = vim.bo.channel + -- 'clear' is used to hide the command + local exitMessage = "\nPress enter to exit..." + local commandString = command() + vim.api.nvim_chan_send(channel, + "clear && " .. commandString .. "; echo '" .. + exitMessage .. "' && read -s && exit" .. "\n") + end end local COMMANDS = {} @@ -29,14 +32,14 @@ function selectCommand(listOfCommands, callback) end }, function(choice) if (choice ~= nil) then - CURRENT_COMMAND = listOfCommands[choice].command() + CURRENT_COMMAND = listOfCommands[choice].command callback() end end) end function executeCommand(listOfCommands) - if (string.len(CURRENT_COMMAND) == 0) then + if (CURRENT_COMMAND == nil) then selectCommand(listOfCommands, function() executeCommandInTerminal(CURRENT_COMMAND) diff --git a/lua/aotrix/personal_commands.lua b/lua/aotrix/personal_commands.lua index ac1b038..e1094d5 100644 --- a/lua/aotrix/personal_commands.lua +++ b/lua/aotrix/personal_commands.lua @@ -1,9 +1,11 @@ return { createCommand = function(COMMANDS) + local selectedCommand = vim.fn.input('Enter a command: ') + local selectedDescription = "Say a nice word" COMMANDS.Flower = { - command = "echo 'coucou'", - description = "Say a nice word" + command = function() return selectedCommand end, + description = function() return selectedDescription end } - return COMMANDS.Flower.command + return COMMANDS.Flower.command() end } |
