feat: Add support for multiple lazygit config files

Lazygit supports using multiple config files: https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md?plain=1#L346

This commit adds code to parse vim.g.lazygit_config_file_path as a `string | table`,
then passes the files to `lazygit` via the `-ucf` flag
This commit is contained in:
Srivatsan Ramaswamy
2023-09-02 11:24:17 +05:30
committed by Dheepak Krishnamurthy
parent 75c920883f
commit de35012036
3 changed files with 62 additions and 28 deletions

View File

@@ -92,6 +92,30 @@ local function is_symlink()
return resolved ~= fn.expand('%:p')
end
local function open_or_create_config(path)
if fn.empty(fn.glob(path)) == 1 then
-- file does not exist
-- check if user wants to create it
local answer = fn.confirm(
"File "
.. path
.. " does not exist.\nDo you want to create the file and populate it with the default configuration?",
"&Yes\n&No"
)
if answer == 2 then
return nil
end
if fn.isdirectory(fn.fnamemodify(path, ":h")) == false then
-- directory does not exist
fn.mkdir(fn.fnamemodify(path, ":h"), "p")
end
vim.cmd("edit " .. path)
vim.cmd([[execute "silent! 0read !lazygit -c"]])
vim.cmd([[execute "normal 1G"]])
else
vim.cmd("edit " .. path)
end
end
return {
get_root = get_root,
@@ -99,4 +123,5 @@ return {
lazygit_visited_git_repos = lazygit_visited_git_repos,
is_lazygit_available = is_lazygit_available,
is_symlink = is_symlink,
open_or_create_config = open_or_create_config,
}