refactor: improved git branching

main
olimorris 2022-06-25 14:07:00 +01:00
parent d093a835ef
commit 3a5f182086
1 changed files with 3 additions and 8 deletions

View File

@ -58,15 +58,10 @@ local function get_branch()
local git_enabled = (vim.fn.isdirectory(vim.fn.getcwd() .. "/.git") == 1)
if config.options.use_git_branch and git_enabled then
local branch = vim.api.nvim_exec([[!git rev-parse --abbrev-ref HEAD 2>/dev/null]], true)
-- The branch command returns two lines. We only need the second one
local lines = {}
for s in branch:gmatch("[^\r\n]+") do
table.insert(lines, "_" .. s)
local branch = vim.fn.systemlist([[git rev-parse --abbrev-ref HEAD 2>/dev/null]])
if vim.v.shell_error == 0 then
return "_" .. branch[1]:gsub("/", "%%")
end
return lines[#lines]:gsub("/", "%%")
end
return "_" .. default_branch