summaryrefslogtreecommitdiff
path: root/lua/aotrix
diff options
context:
space:
mode:
Diffstat (limited to 'lua/aotrix')
-rw-r--r--lua/aotrix/build.lua21
1 files changed, 12 insertions, 9 deletions
diff --git a/lua/aotrix/build.lua b/lua/aotrix/build.lua
index d1b10a6..91b2504 100644
--- a/lua/aotrix/build.lua
+++ b/lua/aotrix/build.lua
@@ -29,10 +29,13 @@ local readJsonFromFile = function(filePath)
return nil
end
-local writeTableToJsonFile = function(table, filePath)
- local file, error = io.open(filePath, 'w')
+local addCommandToJsonFile = function(command, commandsFilePath, directory)
+ local current_json = readJsonFromFile(commandsFilePath)
+ current_json["hihi"] = 2
+ local file, error = io.open(commandsFilePath, 'w')
if file then
- file:write(vim.json.encode(table))
+ 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)
@@ -40,9 +43,7 @@ local writeTableToJsonFile = function(table, filePath)
end
local appendCommandsFromFile = function(commands, commandsFilePath, directory)
- local personal_commands_path = commandsFilePath
- local current_list_of_commands_json = readJsonFromFile(
- personal_commands_path)
+ 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
@@ -56,12 +57,14 @@ local appendCommandsFromFile = function(commands, commandsFilePath, directory)
end
local COMMANDS = {}
-appendCommandsFromFile(COMMANDS, data_path .. "/personal_commands.json",
- vim.fn.getcwd())
+PERSONAL_COMMAND_JSON_PATH = data_path .. "/personal_commands.json"
+appendCommandsFromFile(COMMANDS, PERSONAL_COMMAND_JSON_PATH, vim.fn.getcwd())
local personalCommands = require("aotrix.personal_commands")
COMMANDS.AddCommand = {
command = function()
- CURRENT_COMMAND = personalCommands.createCommand(COMMANDS).command
+ local created_command = personalCommands.createCommand(COMMANDS)
+ addCommandToJsonFile(created_command, PERSONAL_COMMAND_JSON_PATH)
+ CURRENT_COMMAND = created_command.command
return CURRENT_COMMAND()
end,
description = function() return "Add command" end