2021-01-04 00:38:01 +00:00
|
|
|
local async = require('lualine.async')
|
|
|
|
|
|
|
|
local branch
|
|
|
|
|
|
|
|
local git_branch = async:new({
|
|
|
|
cmd = 'git branch --show-current',
|
|
|
|
on_stdout = function(_, data)
|
|
|
|
if data then
|
|
|
|
branch = data:gsub('\n', '')
|
|
|
|
end
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
2021-01-04 00:38:01 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
local timer = vim.loop.new_timer()
|
|
|
|
timer:start(0, 1000, vim.schedule_wrap(function()
|
|
|
|
git_branch:start()
|
|
|
|
end))
|
|
|
|
|
|
|
|
local function Branch()
|
|
|
|
if not branch or #branch == 0 then return '' end
|
2020-12-30 14:48:51 +00:00
|
|
|
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'))
|
2020-12-31 03:12:40 +00:00
|
|
|
if ok ~= 0 then
|
2020-12-30 14:48:51 +00:00
|
|
|
local icon = ''
|
|
|
|
return icon .. ' ' .. branch
|
|
|
|
end
|
|
|
|
return branch
|
|
|
|
end
|
|
|
|
|
|
|
|
return Branch
|