nvim-config/lua/configs/lualine.lua
2024-03-19 17:47:26 -07:00

171 lines
4.2 KiB
Lua

local function config()
local lualine = require('lualine')
local gitblame = require('gitblame')
local scolors = {
fg = '#adb0b9',
fg_wash = '#808289',
bg = '#252526',
inset = '#569cd6',
working_dir = '#569cd6',
branch = '#808289',
filetype = '#c5a6c0',
filename = '#91bde1',
added = '#6a9955',
modified = '#db812e',
removed = '#f6635a',
error = '#f53226',
warn = '#eed94e',
info = '#569cd6',
treesitter = '#6a9955',
scroll = '#dcdcaa',
}
local conditions = {
buffer_not_empty = function()
return vim.fn.empty(vim.fn.expand('%:t')) ~= 1
end,
hide_in_width = function()
return vim.fn.winwidth(0) > 80
end,
check_git_workspace = function()
local filepath = vim.fn.expand('%:p:h')
local gitdir = vim.fn.finddir('.git', filepath .. ';')
return gitdir and #gitdir > 0 and #gitdir < #filepath
end,
}
local opts = {
options = {
disabled_filetypes = { 'neo-tree', 'dashboard' },
component_separators = '',
section_separators = '',
theme = {
normal = { c = { fg = scolors.fg, bg = scolors.bg } },
inactive = { c = { fg = scolors.fg, bg = scolors.bg } },
},
},
sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {
{ -- working dir
function()
local cwd = vim.fn.getcwd()
-- substr the cwd starting at the last "/" character
local cwd_name = string.sub(cwd, -cwd:reverse():find('/') + 1)
return cwd_name
end,
color = { fg = scolors.working_dir, gui = 'bold' },
icon = '',
padding = { left = 2, right = 1 },
},
{ -- file name
'filename',
path = 1,
icon = '',
color = { fg = scolors.filename, gui = 'bold' },
padding = { left = 1, right = 1 },
},
{ -- filetype
'filetype',
colored = false,
color = { fg = scolors.filetype, gui = 'bold' },
cond = conditions.buffer_not_empty,
padding = { left = 1, right = 1 },
},
{ -- git diff
'diff',
symbols = { added = '', modified = '', removed = '' },
diff_color = {
added = { fg = scolors.added },
modified = { fg = scolors.modified },
removed = { fg = scolors.removed },
},
cond = conditions.hide_in_width,
padding = { left = 1, right = 1 },
},
{ -- nvim diagnostics
'diagnostics',
sources = { 'nvim_diagnostic' },
symbols = { error = '', warn = '', info = '', hint = '' },
diagnostics_color = {
color_error = { fg = scolors.error },
color_warn = { fg = scolors.warn },
color_info = { fg = scolors.info },
},
padding = { left = 1, right = 1 },
},
},
lualine_x = {
{ -- git blame
function()
local blame_text = gitblame.get_current_blame_text()
blame_text = blame_text:gsub('Not Committed Yet', 'not committed')
return blame_text
end,
color = { fg = scolors.fg_wash },
cond = gitblame.is_blame_text_available,
padding = { left = 0, right = 1 },
},
{ -- git branch
'branch',
icon = '',
color = { fg = scolors.branch, gui = 'bold' },
padding = { left = 1, right = 1 },
},
{ -- location in file (line:col)
'location',
padding = { left = 0, right = 1 },
},
{ -- progress through file (%)
-- slightly modified from default "progress"
-- always 3 chars long, no TOP
-- https://github.com/nvim-lualine/lualine.nvim/blob/master/lua/lualine/components/progress.lua
function()
local cur = vim.fn.line('.')
local total = vim.fn.line('$')
if cur == total then
return 'BOT'
elseif cur / total < 0.10 then
return ' ' .. math.floor(cur / total * 100) .. '%%'
else
return math.floor(cur / total * 100) .. '%%'
end
end,
'progress',
color = { gui = 'none' },
padding = { left = 0, right = 1 },
},
},
lualine_y = {},
lualine_z = {},
},
inactive_sections = {
lualine_a = {
{ -- file name
'filename',
path = 1,
icon = '',
color = { fg = scolors.filename, gui = 'bold' },
padding = { left = 1, right = 1 },
},
},
lualine_b = {},
lualine_c = {},
lualine_x = {},
lualine_y = {},
lualine_z = {},
},
}
lualine.setup(opts)
end
return config