Merge pull request #71 from thefux/master
#69 add custom config file support
This commit is contained in:
@@ -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_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_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_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.
|
Call `:LazyGit` to start a floating window with `lazygit` in the current working directory.
|
||||||
|
|||||||
@@ -46,6 +46,40 @@ local function exec_lazygit_command(cmd)
|
|||||||
vim.cmd 'startinsert'
|
vim.cmd 'startinsert'
|
||||||
end
|
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
|
--- :LazyGit entry point
|
||||||
local function lazygit(path)
|
local function lazygit(path)
|
||||||
@@ -63,6 +97,10 @@ local function lazygit(path)
|
|||||||
-- set path to the root path
|
-- set path to the root path
|
||||||
_ = project_root_dir()
|
_ = project_root_dir()
|
||||||
|
|
||||||
|
-- print(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()
|
||||||
@@ -104,15 +142,11 @@ local function lazygitfiltercurrentfile()
|
|||||||
lazygitfilter(current_file)
|
lazygitfilter(current_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- :LazyGitConfig entry point
|
--- :LazyGitConfig entry point
|
||||||
local function lazygitconfig()
|
local function lazygitconfig()
|
||||||
local os = fn.substitute(fn.system('uname'), '\n', '', '')
|
local config_file = lazygitgetconfigpath()
|
||||||
local config_file = ''
|
|
||||||
if os == 'Darwin' then
|
|
||||||
config_file = '~/Library/Application Support/jesseduffield/lazygit/config.yml'
|
|
||||||
else
|
|
||||||
config_file = '~/.config/lazygit/config.yml'
|
|
||||||
end
|
|
||||||
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
|
||||||
|
|||||||
@@ -23,6 +23,12 @@ if !exists('g:lazygit_floating_window_corner_chars')
|
|||||||
let g:lazygit_floating_window_corner_chars = ['╭', '╮', '╰', '╯']
|
let g:lazygit_floating_window_corner_chars = ['╭', '╮', '╰', '╯']
|
||||||
endif
|
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! LazyGit lua require'lazygit'.lazygit()
|
||||||
|
|
||||||
command! LazyGitCurrentFile lua require'lazygit'.lazygitcurrentfile()
|
command! LazyGitCurrentFile lua require'lazygit'.lazygitcurrentfile()
|
||||||
|
|||||||
Reference in New Issue
Block a user