diff --git a/README.md b/README.md index 028eaa0..405d05e 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,9 @@ let g:lazygit_floating_window_scaling_factor = 0.9 " scaling factor for floating let g:lazygit_floating_window_corner_chars = ['╭', '╮', '╰', '╯'] " customize lazygit popup window corner characters let g:lazygit_floating_window_use_plenary = 0 " use plenary.nvim to manage floating window if available let g:lazygit_use_neovim_remote = 1 " fallback to 0 if neovim-remote is not installed + +let g:lazygit_use_custom_config_file_path = 0 " config file path is evaluated if this value is 1 +let g:lazygit_config_file_path = '' " custom config file path ``` Call `:LazyGit` to start a floating window with `lazygit` in the current working directory. diff --git a/lua/lazygit.lua b/lua/lazygit.lua index 4c1b16f..2725286 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -46,6 +46,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) @@ -63,6 +97,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() @@ -104,15 +142,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 ef1fac2..5e5c154 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! LazyGitCurrentFile lua require'lazygit'.lazygitcurrentfile()