From fb3f98f8053a4fe94fdf712ac9fc541dff4ba9d5 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Wed, 8 Apr 2020 14:02:29 -0600 Subject: [PATCH] Add LazyGitConfig command --- lua/lazygit.lua | 28 ++++++++++++++++++++++++++++ plugin/lazygit.vim | 2 ++ 2 files changed, 30 insertions(+) diff --git a/lua/lazygit.lua b/lua/lazygit.lua index d95f909..5297e80 100644 --- a/lua/lazygit.lua +++ b/lua/lazygit.lua @@ -116,9 +116,37 @@ local function setup() OPTIONS.lazygit_floating_window_scaling_factor = api.nvim_get_var("lazygit_floating_window_scaling_factor")[false] end +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/jesseduffield/lazygit/config.yml" + end + if fn.empty(fn.glob(config_file)) then + -- file does not exist + -- check if user wants to create it + local answer = fn.confirm("File " .. config_file .. " 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(config_file, ":h")) == false then + -- directory does not exist + fn.mkdir(fn.fnamemodify(config_file, ":h")) + end + vim.cmd("edit " .. config_file) + vim.cmd([[execute "silent! 0read !lazygit -c"]]) + vim.cmd([[execute "normal 1G"]]) + else + vim.cmd("edit " .. config_file) + end +end + return { setup = setup, lazygit = lazygit, + lazygitconfig = lazygitconfig, on_exit = on_exit, on_buf_leave = on_buf_leave, } diff --git a/plugin/lazygit.vim b/plugin/lazygit.vim index a85cbc5..c085637 100644 --- a/plugin/lazygit.vim +++ b/plugin/lazygit.vim @@ -19,6 +19,8 @@ lua require 'lazygit'.setup() command! LazyGit lua require'lazygit'.lazygit() +command! LazyGitConfig lua require'lazygit'.lazygitconfig() + """""""""""""""""""""""""""""""""""""""""""""""""""""" let &cpoptions = s:save_cpo