From 2c7621e4f946edb2c16088a2235601f63f74eadf Mon Sep 17 00:00:00 2001 From: thefux Date: Sun, 4 Sep 2022 20:10:37 +0200 Subject: [PATCH] #69 add custom config file support --- lua/lazygit.lua | 48 +++++++++++++++++++++++++++++++++++++++------- plugin/lazygit.vim | 6 ++++++ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index 7a773a1..a93d8af 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -37,6 +37,40 @@ local function exec_lazygit_command(cmd) vim.cmd 'startinsert' 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/jesseduffield/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 + +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') + end + end + + -- any issue with the config file we fallback to the default config file path + return lazygitdefaultconfigpath() +end --- :LazyGit entry point local function lazygit(path) @@ -54,6 +88,10 @@ local function lazygit(path) -- set path to the root path _ = project_root_dir() + -- print(lazygitgetconfigpath()) + + cmd = cmd .. ' -ucf ' .. lazygitgetconfigpath() + if path == nil then if is_symlink() then path = project_root_dir() @@ -88,15 +126,11 @@ local function lazygitfiltercurrentfile() lazygitfilter(current_file) end + --- :LazyGitConfig entry point local function lazygitconfig() - local os = fn.substitute(fn.system('uname'), '\n', '', '') - local config_file = '' - if os == 'Darwin' then - config_file = '~/Library/Application Support/jesseduffield/lazygit/config.yml' - else - config_file = '~/.config/lazygit/config.yml' - end + local config_file = lazygitgetconfigpath() + if fn.empty(fn.glob(config_file)) == 1 then -- file does not exist -- check if user wants to create it diff --git a/plugin/lazygit.vim b/plugin/lazygit.vim index 2722161..1bda20b 100644 --- a/plugin/lazygit.vim +++ b/plugin/lazygit.vim @@ -23,6 +23,12 @@ if !exists('g:lazygit_floating_window_corner_chars') let g:lazygit_floating_window_corner_chars = ['╭', '╮', '╰', '╯'] endif +" if lazygit_use_custom_config_file_path is set to 1 the +" lazygit_config_file_path option will be evaluated +let g:lazygit_use_custom_config_file_path = 0 +" path to custom config file +let g:lazygit_config_file_path = '' + command! LazyGit lua require'lazygit'.lazygit() command! LazyGitFilter lua require'lazygit'.lazygitfilter()