fix: Change default lazygit config directory 🐛

This commit is contained in:
Dheepak Krishnamurthy
2022-11-02 08:27:28 -04:00
parent cd3f79f4ce
commit e2b1e4c231

View File

@@ -1,8 +1,8 @@
local open_floating_window = require"lazygit.window".open_floating_window
local project_root_dir = require"lazygit.utils".project_root_dir
local get_root = require"lazygit.utils".get_root
local is_lazygit_available = require"lazygit.utils".is_lazygit_available
local is_symlink = require"lazygit.utils".is_symlink
local open_floating_window = require("lazygit.window").open_floating_window
local project_root_dir = require("lazygit.utils").project_root_dir
local get_root = require("lazygit.utils").get_root
local is_lazygit_available = require("lazygit.utils").is_lazygit_available
local is_symlink = require("lazygit.utils").is_symlink
local fn = vim.fn
@@ -22,7 +22,7 @@ local function on_exit(job_id, code, event)
LAZYGIT_BUFFER = nil
LAZYGIT_LOADED = false
vim.g.lazygit_opened = 0
vim.cmd('silent! :checktime')
vim.cmd("silent! :checktime")
if vim.api.nvim_win_is_valid(prev_win) then
vim.api.nvim_win_close(win, true)
@@ -43,7 +43,7 @@ local function exec_lazygit_command(cmd)
vim.g.lazygit_opened = 1
vim.fn.termopen(cmd, { on_exit = on_exit })
end
vim.cmd 'startinsert'
vim.cmd("startinsert")
end
local function lazygitdefaultconfigpath()
@@ -51,14 +51,14 @@ local function lazygitdefaultconfigpath()
-- 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'
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'
if string.find(os_name, "Window") then
return "%APPDATA%/lazygit/config.yml"
else
return '~/.config/lazygit/config.yml'
return "~/.config/lazygit/config.yml"
end
end
end
@@ -71,9 +71,9 @@ local function lazygitgetconfigpath()
return vim.g.lazygit_config_file_path
end
print('lazygit: custom config file path: \'' .. vim.g.lazygit_config_file_path .. '\' could not be found')
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')
print("lazygit: custom config file path is not set, option: 'lazygit_config_file_path' is missing")
end
end
@@ -84,7 +84,7 @@ end
--- :LazyGit entry point
local function lazygit(path)
if is_lazygit_available() ~= true then
print('Please install lazygit. Check documentation for more information')
print("Please install lazygit. Check documentation for more information")
return
end
@@ -92,23 +92,23 @@ local function lazygit(path)
win, buffer = open_floating_window()
local cmd = 'lazygit'
local cmd = "lazygit"
-- set path to the root path
_ = project_root_dir()
-- print(lazygitgetconfigpath())
cmd = cmd .. ' -ucf ' .. lazygitgetconfigpath()
cmd = cmd .. " -ucf " .. lazygitgetconfigpath()
if path == nil then
if is_symlink() then
path = project_root_dir()
end
else
if fn.isdirectory(path) then
cmd = cmd .. ' -p ' .. path
end
if fn.isdirectory(path) then
cmd = cmd .. " -p " .. path
end
end
exec_lazygit_command(cmd)
@@ -116,7 +116,7 @@ end
--- :LazyGitCurrentFile entry point
local function lazygitcurrentfile()
local current_dir = vim.fn.expand('%:p:h')
local current_dir = vim.fn.expand("%:p:h")
local git_root = get_root(current_dir)
lazygit(git_root)
end
@@ -124,7 +124,7 @@ end
--- :LazyGitFilter entry point
local function lazygitfilter(path)
if is_lazygit_available() ~= true then
print('Please install lazygit. Check documentation for more information')
print("Please install lazygit. Check documentation for more information")
return
end
if path == nil then
@@ -132,17 +132,16 @@ local function lazygitfilter(path)
end
prev_win = vim.api.nvim_get_current_win()
open_floating_window()
local cmd = 'lazygit ' .. '-f ' .. path
local cmd = "lazygit " .. "-f " .. path
exec_lazygit_command(cmd)
end
--- :LazyGitFilterCurrentFile entry point
local function lazygitfiltercurrentfile()
local current_file = vim.fn.expand('%')
local current_file = vim.fn.expand("%")
lazygitfilter(current_file)
end
--- :LazyGitConfig entry point
local function lazygitconfig()
local config_file = lazygitgetconfigpath()
@@ -150,21 +149,24 @@ local function lazygitconfig()
if fn.empty(fn.glob(config_file)) == 1 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')
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
if fn.isdirectory(fn.fnamemodify(config_file, ":h")) == false then
-- directory does not exist
fn.mkdir(fn.fnamemodify(config_file, ':h'), 'p')
fn.mkdir(fn.fnamemodify(config_file, ":h"), "p")
end
vim.cmd('edit ' .. config_file)
vim.cmd("edit " .. config_file)
vim.cmd([[execute "silent! 0read !lazygit -c"]])
vim.cmd([[execute "normal 1G"]])
else
vim.cmd('edit ' .. config_file)
vim.cmd("edit " .. config_file)
end
end