Dotfiles_nvim/lua/util/config.lua

31 lines
713 B
Lua
Raw Normal View History

2024-09-07 23:50:39 +00:00
local C = require('util.const')
local F = require('util.finder')
local CONFIG = {}
CONFIG.config_dir = F.project_dir .. "/" .. C.CONFIG_DIR
function CONFIG.get(module, name)
local config_file_path = CONFIG.config_dir .. module .. ".json"
if vim.fn.filereadable(config_file_path) == 0 then
return nil
end
local config_file = vim.fn.readfile(config_file_path, "")
2024-09-10 07:41:43 +00:00
local success, data = pcall(function()
2024-09-07 23:50:39 +00:00
return vim.json.decode(table.concat(config_file, ""))
end)
2024-09-10 07:41:43 +00:00
if not success or data then
2024-09-07 23:50:39 +00:00
return nil
end
return table.concat(
vim.split(data[name], C.PROJECT_DIR_PLACEHOLDER, { plain = true}),
F.project_dir
)
end
2024-09-10 07:41:43 +00:00
return CONFIG