lualine.nvim/lua/lualine/components/branch.lua

26 lines
699 B
Lua
Raw Normal View History

2020-12-30 14:48:51 +00:00
local function Branch()
local branch = vim.fn.systemlist(
'cd '..vim.fn.expand('%:p:h:S')..' 2>/dev/null && git status --porcelain -b 2>/dev/null')[1]
if not branch or #branch == 0 then
return ''
end
branch = branch:gsub([[^## No commits yet on (%w+)$]], '%1')
branch = branch:gsub([[^##%s+(%w+).*$]], '%1')
local ok,devicons = pcall(require,'nvim-web-devicons')
if ok then
local icon = devicons.get_icon('git')
if icon ~= nil then
return icon .. ' ' .. branch
end
return branch
end
ok = (vim.fn.exists('*WebDevIconsGetFileTypeSymbol'))
if ok ~= 0 then
2020-12-30 14:48:51 +00:00
local icon = ''
return icon .. ' ' .. branch
end
return branch
end
return Branch