aboutsummaryrefslogtreecommitdiff
path: root/nvim/lua/core/statusline.lua
blob: 45a2c421fa591903de31d7d8eacb93ba3e1de931 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
local M = {}

local function git_branch()
	local git_dir = vim.fn.system("git rev-parse --git-dir 2>/dev/null")
	if vim.v.shell_error ~= 0 then
		return ""
	end
	local branch = vim.fn.system("git branch --show-current 2>/dev/null | tr -d '\n'")
	return branch
end

function M.statusline_git()
	local branch_name = git_branch()
	return #branch_name > 0 and '  ' .. branch_name .. ' ' or ''
end

function M.setup()
	vim.cmd('highlight clear StatusLine')
	vim.cmd('highlight clear StatusLineNC')

	local highlights = {
		StatusLineGit      = { bg = "#161616", fg = "#D8DEE9" },
		StatusLineBuffer   = { bg = "NONE",    fg = "#D8DEE9" },
		StatusLine         = { bg = "NONE",    fg = "#D8DEE9" },
		StatusLineFiletype = { bg = "NONE",    fg = "#D8DEE9" },
		StatusLinePath     = { bg = "NONE",    fg = "#D8DEE9" },
		StatusLineModified = { bg = "NONE",    fg = "#D8DEE9" },
	}

	for name, colors in pairs(highlights) do
		vim.api.nvim_set_hl(0, name, colors)
	end

	vim.opt.statusline = table.concat({
		"%#StatusLineGit#%{v:lua.require'core.statusline'.statusline_git()}",
		"%#StatusLineBuffer# %n ",
		"%#StatusLine#%{&ff} ",
		"%#StatusLineFiletype#%y",
		"%#StatusLinePath# %<%{expand('%:p:h')}/%f",
		"%#StatusLineModified#%m",
		"%=",
		"%#StatusLine#%5l",
		"/%L:%v ",
		"%{char2nr(getline('.')[col('.')-1])} "
	})
end

vim.api.nvim_create_autocmd("ColorScheme", {
	pattern = "*",
	callback = function()
		M.setup()
	end,
})

return M