summaryrefslogtreecommitdiff
path: root/lua/aotrix
diff options
context:
space:
mode:
Diffstat (limited to 'lua/aotrix')
-rw-r--r--lua/aotrix/plugins/build.lua25
1 files changed, 9 insertions, 16 deletions
diff --git a/lua/aotrix/plugins/build.lua b/lua/aotrix/plugins/build.lua
index f178e4e..61dceb4 100644
--- a/lua/aotrix/plugins/build.lua
+++ b/lua/aotrix/plugins/build.lua
@@ -71,28 +71,21 @@ return {
local addCommandToJsonFile = function(commandBlock, commandsFilePath,
directory)
local current_json = readJsonFromFile(commandsFilePath)
- local is_new_file = false
- 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())
- })
- else
- is_new_file = true
+ if current_json == nil then current_json = {} end
+ 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())
+ })
local file, error = io.open(commandsFilePath, 'w')
- if is_new_file and file ~= nil then file:write("{}") end
if file then
local indent =
vim.bo.expandtab and (' '):rep(vim.o.shiftwidth) or '\t'
if current_json ~= nil then
- json_content = vim.json.encode(current_json,
- {indent = indent})
- file:write(json_content)
+ file:write(vim.json.encode(current_json, {indent = indent}))
end
file:close()
else