From 56045b4a0d8fa7bfee37411267ca5c6d3c1fe789 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Wed, 2 Nov 2022 08:34:49 -0400 Subject: [PATCH] =?UTF-8?q?feat:=20change=20custom=20config=20file=20logic?= =?UTF-8?q?=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/lazygit.lua | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index 5c5cb47..c3310b0 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -47,34 +47,19 @@ local function exec_lazygit_command(cmd) end local function lazygitdefaultconfigpath() - local os_name = vim.loop.os_uname().sysname - - -- 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 + return fn.substitute(fn.system("lazygit -cd"), "\n", "", "") end local function lazygitgetconfigpath() - if vim.g.lazygit_use_custom_config_file_path == 1 then - if vim.g.lazygit_config_file_path then - -- if file exists - if fn.empty(fn.glob(vim.g.lazygit_config_file_path)) == 0 then - 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") + if vim.g.lazygit_config_file_path then + -- if file exists + if fn.empty(fn.glob(vim.g.lazygit_config_file_path)) == 0 then + 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 -- 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 _ = project_root_dir() - -- print(lazygitgetconfigpath()) - - cmd = cmd .. " -ucf " .. lazygitgetconfigpath() + if vim.g.lazygit_use_custom_config_file_path == 1 then + cmd = cmd .. " -ucf " .. lazygitgetconfigpath() + end if path == nil then if is_symlink() then