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

38 lines
825 B
Lua
Raw Normal View History

local async = require('lualine.async')
local git_branch
local get_git_branch = async:new({
cmd = 'git branch --show-current',
on_stdout = function(_, data)
if data then
git_branch = data:gsub('\n', '')
end
2020-12-30 14:48:51 +00:00
end
})
local timer = vim.loop.new_timer()
timer:start(0, 1000, vim.schedule_wrap(function()
get_git_branch:start()
end))
local function branch()
if not git_branch or #git_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 .. ' ' .. git_branch
2020-12-30 14:48:51 +00:00
end
return git_branch
2020-12-30 14:48:51 +00:00
end
2021-01-05 23:43:36 +00:00
ok = vim.fn.exists("*WebDevIconsGetFileTypeSymbol")
if ok ~= 0 then
2020-12-30 14:48:51 +00:00
local icon = ''
return icon .. ' ' .. git_branch
2020-12-30 14:48:51 +00:00
end
return git_branch
2020-12-30 14:48:51 +00:00
end
return branch