fix: Change default lazygit config directory 🐛
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
local open_floating_window = require"lazygit.window".open_floating_window
|
local open_floating_window = require("lazygit.window").open_floating_window
|
||||||
local project_root_dir = require"lazygit.utils".project_root_dir
|
local project_root_dir = require("lazygit.utils").project_root_dir
|
||||||
local get_root = require"lazygit.utils".get_root
|
local get_root = require("lazygit.utils").get_root
|
||||||
local is_lazygit_available = require"lazygit.utils".is_lazygit_available
|
local is_lazygit_available = require("lazygit.utils").is_lazygit_available
|
||||||
local is_symlink = require"lazygit.utils".is_symlink
|
local is_symlink = require("lazygit.utils").is_symlink
|
||||||
|
|
||||||
local fn = vim.fn
|
local fn = vim.fn
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ local function on_exit(job_id, code, event)
|
|||||||
LAZYGIT_BUFFER = nil
|
LAZYGIT_BUFFER = nil
|
||||||
LAZYGIT_LOADED = false
|
LAZYGIT_LOADED = false
|
||||||
vim.g.lazygit_opened = 0
|
vim.g.lazygit_opened = 0
|
||||||
vim.cmd('silent! :checktime')
|
vim.cmd("silent! :checktime")
|
||||||
|
|
||||||
if vim.api.nvim_win_is_valid(prev_win) then
|
if vim.api.nvim_win_is_valid(prev_win) then
|
||||||
vim.api.nvim_win_close(win, true)
|
vim.api.nvim_win_close(win, true)
|
||||||
@@ -43,7 +43,7 @@ local function exec_lazygit_command(cmd)
|
|||||||
vim.g.lazygit_opened = 1
|
vim.g.lazygit_opened = 1
|
||||||
vim.fn.termopen(cmd, { on_exit = on_exit })
|
vim.fn.termopen(cmd, { on_exit = on_exit })
|
||||||
end
|
end
|
||||||
vim.cmd 'startinsert'
|
vim.cmd("startinsert")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function lazygitdefaultconfigpath()
|
local function lazygitdefaultconfigpath()
|
||||||
@@ -51,14 +51,14 @@ local function lazygitdefaultconfigpath()
|
|||||||
|
|
||||||
-- TODO: not surer if vim.loop.os_uname() has the same result
|
-- TODO: not surer if vim.loop.os_uname() has the same result
|
||||||
-- check before replacing the following line
|
-- check before replacing the following line
|
||||||
local os = fn.substitute(fn.system('uname'), '\n', '', '')
|
local os = fn.substitute(fn.system("uname"), "\n", "", "")
|
||||||
if os == 'Darwin' then
|
if os == "Darwin" then
|
||||||
return '~/Library/Application\\ Support/jesseduffield/lazygit/config.yml'
|
return "~/Library/Application Support/lazygit/config.yml"
|
||||||
else
|
else
|
||||||
if string.find(os_name, 'Window') then
|
if string.find(os_name, "Window") then
|
||||||
return '%APPDATA%/lazygit/config.yml'
|
return "%APPDATA%/lazygit/config.yml"
|
||||||
else
|
else
|
||||||
return '~/.config/lazygit/config.yml'
|
return "~/.config/lazygit/config.yml"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -71,9 +71,9 @@ local function lazygitgetconfigpath()
|
|||||||
return vim.g.lazygit_config_file_path
|
return vim.g.lazygit_config_file_path
|
||||||
end
|
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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ end
|
|||||||
--- :LazyGit entry point
|
--- :LazyGit entry point
|
||||||
local function lazygit(path)
|
local function lazygit(path)
|
||||||
if is_lazygit_available() ~= true then
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -92,23 +92,23 @@ local function lazygit(path)
|
|||||||
|
|
||||||
win, buffer = open_floating_window()
|
win, buffer = open_floating_window()
|
||||||
|
|
||||||
local cmd = 'lazygit'
|
local cmd = "lazygit"
|
||||||
|
|
||||||
-- set path to the root path
|
-- set path to the root path
|
||||||
_ = project_root_dir()
|
_ = project_root_dir()
|
||||||
|
|
||||||
-- print(lazygitgetconfigpath())
|
-- print(lazygitgetconfigpath())
|
||||||
|
|
||||||
cmd = cmd .. ' -ucf ' .. lazygitgetconfigpath()
|
cmd = cmd .. " -ucf " .. lazygitgetconfigpath()
|
||||||
|
|
||||||
if path == nil then
|
if path == nil then
|
||||||
if is_symlink() then
|
if is_symlink() then
|
||||||
path = project_root_dir()
|
path = project_root_dir()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if fn.isdirectory(path) then
|
if fn.isdirectory(path) then
|
||||||
cmd = cmd .. ' -p ' .. path
|
cmd = cmd .. " -p " .. path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
exec_lazygit_command(cmd)
|
exec_lazygit_command(cmd)
|
||||||
@@ -116,7 +116,7 @@ end
|
|||||||
|
|
||||||
--- :LazyGitCurrentFile entry point
|
--- :LazyGitCurrentFile entry point
|
||||||
local function lazygitcurrentfile()
|
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)
|
local git_root = get_root(current_dir)
|
||||||
lazygit(git_root)
|
lazygit(git_root)
|
||||||
end
|
end
|
||||||
@@ -124,7 +124,7 @@ end
|
|||||||
--- :LazyGitFilter entry point
|
--- :LazyGitFilter entry point
|
||||||
local function lazygitfilter(path)
|
local function lazygitfilter(path)
|
||||||
if is_lazygit_available() ~= true then
|
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
|
return
|
||||||
end
|
end
|
||||||
if path == nil then
|
if path == nil then
|
||||||
@@ -132,17 +132,16 @@ local function lazygitfilter(path)
|
|||||||
end
|
end
|
||||||
prev_win = vim.api.nvim_get_current_win()
|
prev_win = vim.api.nvim_get_current_win()
|
||||||
open_floating_window()
|
open_floating_window()
|
||||||
local cmd = 'lazygit ' .. '-f ' .. path
|
local cmd = "lazygit " .. "-f " .. path
|
||||||
exec_lazygit_command(cmd)
|
exec_lazygit_command(cmd)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- :LazyGitFilterCurrentFile entry point
|
--- :LazyGitFilterCurrentFile entry point
|
||||||
local function lazygitfiltercurrentfile()
|
local function lazygitfiltercurrentfile()
|
||||||
local current_file = vim.fn.expand('%')
|
local current_file = vim.fn.expand("%")
|
||||||
lazygitfilter(current_file)
|
lazygitfilter(current_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- :LazyGitConfig entry point
|
--- :LazyGitConfig entry point
|
||||||
local function lazygitconfig()
|
local function lazygitconfig()
|
||||||
local config_file = lazygitgetconfigpath()
|
local config_file = lazygitgetconfigpath()
|
||||||
@@ -150,21 +149,24 @@ local function lazygitconfig()
|
|||||||
if fn.empty(fn.glob(config_file)) == 1 then
|
if fn.empty(fn.glob(config_file)) == 1 then
|
||||||
-- file does not exist
|
-- file does not exist
|
||||||
-- check if user wants to create it
|
-- check if user wants to create it
|
||||||
local answer = fn.confirm('File ' .. config_file
|
local answer = fn.confirm(
|
||||||
.. ' does not exist.\nDo you want to create the file and populate it with the default configuration?',
|
"File "
|
||||||
'&Yes\n&No')
|
.. 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
|
if answer == 2 then
|
||||||
return nil
|
return nil
|
||||||
end
|
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
|
-- directory does not exist
|
||||||
fn.mkdir(fn.fnamemodify(config_file, ':h'), 'p')
|
fn.mkdir(fn.fnamemodify(config_file, ":h"), "p")
|
||||||
end
|
end
|
||||||
vim.cmd('edit ' .. config_file)
|
vim.cmd("edit " .. config_file)
|
||||||
vim.cmd([[execute "silent! 0read !lazygit -c"]])
|
vim.cmd([[execute "silent! 0read !lazygit -c"]])
|
||||||
vim.cmd([[execute "normal 1G"]])
|
vim.cmd([[execute "normal 1G"]])
|
||||||
else
|
else
|
||||||
vim.cmd('edit ' .. config_file)
|
vim.cmd("edit " .. config_file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user