summaryrefslogtreecommitdiff
path: root/lua/aotrix/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'lua/aotrix/plugins')
-rw-r--r--lua/aotrix/plugins/build.lua283
1 files changed, 0 insertions, 283 deletions
diff --git a/lua/aotrix/plugins/build.lua b/lua/aotrix/plugins/build.lua
deleted file mode 100644
index ad31be7..0000000
--- a/lua/aotrix/plugins/build.lua
+++ /dev/null
@@ -1,283 +0,0 @@
-return {
- "MunifTanjim/nui.nvim",
- config = function()
- local COMMANDS = {}
- local CURRENT_COMMAND = nil
- local data_path = vim.fn.stdpath("data")
- local PERSONAL_COMMAND_JSON_PATH = data_path ..
- "/personal_commands.json"
-
- ---@param command string|nil
- ---@return nil
- local executeCommandInTerminal = function(command)
- 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 readJsonFromFile = function(filePath)
- local file, error = io.open(filePath, 'r')
- if file ~= nil then
- local content = file:read("*a")
- local decoded_json = vim.json.decode(content)
- return decoded_json
- else
- print("Error in readJsonFromFile: " .. error)
- end
- return nil
- end
-
- local addCommandToJsonFile = function(commandBlock, commandsFilePath,
- directory)
- local current_json = readJsonFromFile(commandsFilePath)
- if current_json ~= nil then
- if current_json[directory] == nil then
- current_json[directory] = {}
- end
- -- FIXME: duplicates
- table.insert(current_json[directory], {
- command = tostring(commandBlock.command()),
- description = tostring(commandBlock.description())
- })
- end
- local file, error = io.open(commandsFilePath, 'w')
- if file then
- local indent =
- vim.bo.expandtab and (' '):rep(vim.o.shiftwidth) or '\t'
- file:write(vim.json.encode(current_json, {indent = indent}))
- file:close()
- else
- print("Error in writeTableToJsonFile: " .. error)
- end
- end
-
- local updateJsonFile = function(listOfCommands, commandsFilePath,
- directory)
- local current_json = readJsonFromFile(commandsFilePath)
- current_json[directory] = {}
- for _, value in pairs(listOfCommands) do
- table.insert(current_json[directory], {
- command = tostring(value.command()),
- description = tostring(value.description())
- })
- end
-
- local file, error = io.open(commandsFilePath, 'w')
- if file then
- local indent =
- vim.bo.expandtab and (' '):rep(vim.o.shiftwidth) or '\t'
- file:write(vim.json.encode(current_json, {indent = indent}))
- file:close()
- else
- print("Error in updateJsonFile: " .. error)
- end
- end
-
- local appendCommandsFromFile = function(commands, commandsFilePath,
- directory)
- local current_list_of_commands_json = readJsonFromFile(
- commandsFilePath)
- if current_list_of_commands_json ~= nil and
- current_list_of_commands_json[directory] ~= nil then
- for _, block in pairs(current_list_of_commands_json[directory]) do
- local new_command_name = block["description"]
- commands[new_command_name] = {
- command = function()
- return block["command"]
- end,
- description = function()
- return new_command_name
- end
- }
- end
- end
- end
-
- local selectCommand = function(listOfCommands, callback)
- local Menu = require("nui.menu")
- local commandDescriptions = {}
- for title, _ in pairs(listOfCommands) do
- table.insert(commandDescriptions, Menu.item(title))
- end
- local menu = Menu({
- position = "50%",
- size = {width = "80%", height = "80%"},
- border = {
- style = "single",
- text = {top = "[Choose a command]", top_align = "center"}
- },
- win_options = {
- winhighlight = "Normal:Normal,FloatBorder:Normal"
- }
- }, {
- lines = commandDescriptions,
- max_width = 100,
- keymap = {
- focus_next = {"j", "<Down>", "<Tab>"},
- focus_prev = {"k", "<Up>", "<S-Tab>"},
- close = {"<Esc>", "<C-c>"},
- submit = {"<CR>", "<Space>"}
- },
- on_submit = function(item)
- CURRENT_COMMAND = listOfCommands[item.text].command
- callback(item.text)
- end
- })
- menu:mount()
- end
-
- local addCommand = function(commands, personal_command_json_path)
-
- local selectedCommand = nil
- local Input = require("nui.input")
- local Layout = require("nui.layout")
- local event = require("nui.utils.autocmd").event
- local inputDescription = Input({
- position = "50%",
- size = {width = 120},
- border = {
- style = "single",
- text = {top = "[Enter description]", top_align = "center"}
- },
- win_options = {
- winhighlight = "Normal:Normal,FloatBorder:Normal"
- }
- }, {
- prompt = "> ",
- default_value = "",
- on_submit = function(value)
- local selectedDescription = value
- commands[selectedDescription] = {
- command = function()
- return selectedCommand
- end,
- description = function()
- return selectedDescription
- end
- }
- local created_command = commands[selectedDescription]
- addCommandToJsonFile(created_command,
- personal_command_json_path,
- vim.fn.getcwd())
- CURRENT_COMMAND = created_command.command
- executeCommandInTerminal(CURRENT_COMMAND)
- end
- })
- local input = Input({
- size = {width = 120},
- border = {
- style = "single",
- text = {top = "[Add command]", top_align = "center"}
- },
- win_options = {
- winhighlight = "Normal:Normal,FloatBorder:Normal"
- }
- }, {
- prompt = "> ",
- default_value = "",
- on_submit = function(value)
- selectedCommand = value
- end
- })
- input:map("n", "<Esc>", function() input:unmount() end,
- {noremap = true})
-
- inputDescription:map("n", "<Esc>",
- function()
- inputDescription:unmount()
- end, {noremap = true})
- inputDescription:map("i", "<C-h>", function()
- print("inputDescription: left!")
- end, {noremap = true})
- input:map("i", "<C-l>",
- function() print("inputDescription: right!") end,
- {noremap = true})
-
- inputDescription:on(event.BufEnter, function()
- local insert = vim.api.nvim_replace_termcodes("i", true, true,
- true)
- vim.api.nvim_feedkeys(insert, "t", false)
- end)
-
- local layout = Layout({
- position = "0%",
- size = {width = "100%", height = "100%"}
- }, Layout.Box({
- Layout.Box(input, {size = {width = "50%", height = "100%"}}),
- Layout.Box(inputDescription,
- {size = {width = "50%", height = "100%"}})
- }, {dir = "row"}))
-
- layout:mount()
-
- end
-
- local deleteCommand = function()
- local previous_command = CURRENT_COMMAND
- selectCommand(COMMANDS, function(choice)
- local index = 0
- for key, _ in pairs(COMMANDS) do
- index = index + 1
- if key == choice then
- COMMANDS[key] = nil
- updateJsonFile(COMMANDS, PERSONAL_COMMAND_JSON_PATH,
- vim.fn.getcwd())
- break
- end
- end
- CURRENT_COMMAND = previous_command
- end)
- end
-
- vim.api.nvim_create_user_command("AddCommand", function()
- addCommand(COMMANDS, PERSONAL_COMMAND_JSON_PATH)
- end, {})
-
- vim.api.nvim_create_user_command("DeleteCommand", deleteCommand, {})
-
- vim.api.nvim_create_autocmd({'BufEnter', 'BufWinEnter', 'DirChanged'}, {
- callback = function()
- COMMANDS = {}
- local current_json =
- readJsonFromFile(PERSONAL_COMMAND_JSON_PATH)
- local current_path = vim.fn.getcwd()
- if current_json ~= nil then
- for existing_directory, _ in pairs(current_json) do
- if (current_path == existing_directory or
- string.find(current_path, existing_directory) == 1) then
- appendCommandsFromFile(COMMANDS,
- PERSONAL_COMMAND_JSON_PATH,
- existing_directory)
- end
- end
- end
- end
- })
-
- vim.keymap.set("n", "mc", function()
- if (CURRENT_COMMAND == nil) then
- selectCommand(COMMANDS, function()
- executeCommandInTerminal(CURRENT_COMMAND)
- end)
- else
- executeCommandInTerminal(CURRENT_COMMAND)
- end
- end)
-
- vim.keymap.set("n", "mC", function()
- selectCommand(COMMANDS, function()
- executeCommandInTerminal(CURRENT_COMMAND)
- end)
- end)
-
- end
-}