fix: #96 improve startup time
For those who do not use the git branching feature, this may improve their Neovim startup time significantlymain
parent
5b5ec1c797
commit
d90f9adb04
|
|
@ -41,24 +41,26 @@ end
|
||||||
---Get the current Git branch
|
---Get the current Git branch
|
||||||
---@return string
|
---@return string
|
||||||
function M.get_branch()
|
function M.get_branch()
|
||||||
vim.fn.system([[git rev-parse 2> /dev/null]])
|
if config.options.use_git_branch then
|
||||||
local git_enabled = (vim.v.shell_error == 0)
|
vim.fn.system([[git rev-parse 2> /dev/null]])
|
||||||
|
local git_enabled = (vim.v.shell_error == 0)
|
||||||
|
|
||||||
if config.options.use_git_branch and git_enabled then
|
if git_enabled then
|
||||||
local branch = vim.fn.systemlist([[git rev-parse --abbrev-ref HEAD 2>/dev/null]])
|
local branch = vim.fn.systemlist([[git rev-parse --abbrev-ref HEAD 2>/dev/null]])
|
||||||
if vim.v.shell_error == 0 then
|
if vim.v.shell_error == 0 then
|
||||||
branch = config.options.branch_separator .. branch[1]:gsub("/", "%%")
|
branch = config.options.branch_separator .. branch[1]:gsub("/", "%%")
|
||||||
local branch_session = config.options.save_dir
|
local branch_session = config.options.save_dir
|
||||||
.. vim.fn.getcwd():gsub(utils.get_dir_pattern(), "%%")
|
.. vim.fn.getcwd():gsub(utils.get_dir_pattern(), "%%")
|
||||||
.. branch
|
.. branch
|
||||||
.. ".vim"
|
.. ".vim"
|
||||||
|
|
||||||
-- Try to load the session for the current branch and if not, use the value of default_branch
|
-- Try to load the session for the current branch and if not, use the value of default_branch
|
||||||
if vim.fn.filereadable(branch_session) ~= 0 then
|
if vim.fn.filereadable(branch_session) ~= 0 then
|
||||||
return branch
|
return branch
|
||||||
else
|
else
|
||||||
vim.g.persisted_branch_session = branch_session
|
vim.g.persisted_branch_session = branch_session
|
||||||
return config.options.branch_separator .. default_branch
|
return config.options.branch_separator .. default_branch
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue