feat: change custom config file logic

This commit is contained in:
Dheepak Krishnamurthy
2022-11-02 08:34:49 -04:00
parent 2fd5b526e2
commit 56045b4a0d

View File

@@ -47,34 +47,19 @@ local function exec_lazygit_command(cmd)
end end
local function lazygitdefaultconfigpath() local function lazygitdefaultconfigpath()
local os_name = vim.loop.os_uname().sysname return fn.substitute(fn.system("lazygit -cd"), "\n", "", "")
-- TODO: not surer if vim.loop.os_uname() has the same result
-- check before replacing the following line
local os = fn.substitute(fn.system("uname"), "\n", "", "")
if os == "Darwin" then
return "~/Library/Application\\ Support/lazygit/config.yml"
else
if string.find(os_name, "Window") then
return "%APPDATA%/lazygit/config.yml"
else
return "~/.config/lazygit/config.yml"
end
end
end end
local function lazygitgetconfigpath() local function lazygitgetconfigpath()
if vim.g.lazygit_use_custom_config_file_path == 1 then if vim.g.lazygit_config_file_path then
if vim.g.lazygit_config_file_path then -- if file exists
-- if file exists if fn.empty(fn.glob(vim.g.lazygit_config_file_path)) == 0 then
if fn.empty(fn.glob(vim.g.lazygit_config_file_path)) == 0 then return vim.g.lazygit_config_file_path
return vim.g.lazygit_config_file_path
end
print("lazygit: custom config file path: '" .. vim.g.lazygit_config_file_path .. "' could not be found")
else
print("lazygit: custom config file path is not set, option: 'lazygit_config_file_path' is missing")
end end
print("lazygit: custom config file path: '" .. vim.g.lazygit_config_file_path .. "' could not be found")
else
print("lazygit: custom config file path is not set, option: 'lazygit_config_file_path' is missing")
end end
-- any issue with the config file we fallback to the default config file path -- any issue with the config file we fallback to the default config file path
@@ -97,9 +82,9 @@ local function lazygit(path)
-- set path to the root path -- set path to the root path
_ = project_root_dir() _ = project_root_dir()
-- print(lazygitgetconfigpath()) if vim.g.lazygit_use_custom_config_file_path == 1 then
cmd = cmd .. " -ucf " .. lazygitgetconfigpath()
cmd = cmd .. " -ucf " .. lazygitgetconfigpath() end
if path == nil then if path == nil then
if is_symlink() then if is_symlink() then