Skip to content

Commit

Permalink
fix: #96 improve startup time
Browse files Browse the repository at this point in the history
For those who do not use the git branching feature, this may improve their Neovim startup time significantly
  • Loading branch information
olimorris committed Nov 16, 2023
1 parent 5b5ec1c commit d90f9ad
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions lua/persisted/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,26 @@ end
---Get the current Git branch
---@return string
function M.get_branch()
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
local branch = vim.fn.systemlist([[git rev-parse --abbrev-ref HEAD 2>/dev/null]])
if vim.v.shell_error == 0 then
branch = config.options.branch_separator .. branch[1]:gsub("/", "%%")
local branch_session = config.options.save_dir
.. vim.fn.getcwd():gsub(utils.get_dir_pattern(), "%%")
.. branch
.. ".vim"

-- 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
return branch
else
vim.g.persisted_branch_session = branch_session
return config.options.branch_separator .. default_branch
if config.options.use_git_branch then
vim.fn.system([[git rev-parse 2> /dev/null]])
local git_enabled = (vim.v.shell_error == 0)

if git_enabled then
local branch = vim.fn.systemlist([[git rev-parse --abbrev-ref HEAD 2>/dev/null]])
if vim.v.shell_error == 0 then
branch = config.options.branch_separator .. branch[1]:gsub("/", "%%")
local branch_session = config.options.save_dir
.. vim.fn.getcwd():gsub(utils.get_dir_pattern(), "%%")
.. branch
.. ".vim"

-- 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
return branch
else
vim.g.persisted_branch_session = branch_session
return config.options.branch_separator .. default_branch
end
end
end
end
Expand Down

0 comments on commit d90f9ad

Please sign in to comment.