Dotfiles_nvim/lua/util/config.lua

31 lines
712 B
Lua
Raw Normal View History

2024-09-08 01:50:39 +02:00
local C = require('util.const')
local F = require('util.finder')
local CONFIG = {}
2025-01-13 15:30:01 +01:00
CONFIG.config_dir = F.project_dir .. '/' .. C.CONFIG_DIR
2024-09-08 01:50:39 +02:00
function CONFIG.get(module, name)
2025-01-13 15:30:01 +01:00
local config_file_path = CONFIG.config_dir .. module .. '.json'
2024-09-08 01:50:39 +02:00
if vim.fn.filereadable(config_file_path) == 0 then
return nil
end
2025-01-13 15:30:01 +01:00
local config_file = vim.fn.readfile(config_file_path, '')
2024-09-08 01:50:39 +02:00
local succes, data = pcall(function()
2025-01-13 15:30:01 +01:00
return vim.json.decode(table.concat(config_file, ''))
2024-09-08 01:50:39 +02:00
end)
if not succes or data then
return nil
end
return table.concat(
2025-01-13 15:30:01 +01:00
vim.split(data[name], C.PROJECT_DIR_PLACEHOLDER, { plain = true }),
2024-09-08 01:50:39 +02:00
F.project_dir
)
end
2025-01-13 15:30:01 +01:00
return CONFIG