From 37fce10620f371499bcdb8768ebbf7c73e5be1a1 Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Thu, 23 Jul 2026 22:47:01 +0200 Subject: Add commands from parent dir --- lua/aotrix/build.lua | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'lua') diff --git a/lua/aotrix/build.lua b/lua/aotrix/build.lua index 7e4e173..933c0ce 100644 --- a/lua/aotrix/build.lua +++ b/lua/aotrix/build.lua @@ -131,28 +131,34 @@ vim.api.nvim_create_user_command("AddCommand", addCommand, {}) vim.api.nvim_create_user_command("DeleteCommand", deleteCommand, {}) -local executeCommand = function(listOfCommands) +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 (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(listOfCommands, + selectCommand(COMMANDS, function() executeCommandInTerminal(CURRENT_COMMAND) end) else executeCommandInTerminal(CURRENT_COMMAND) end -end - -vim.api.nvim_create_autocmd({'BufEnter', 'BufWinEnter', 'DirChanged'}, { - callback = function() - COMMANDS = {} - appendCommandsFromFile(COMMANDS, PERSONAL_COMMAND_JSON_PATH, - vim.fn.getcwd()) - 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) - -- cgit v1.2.3