nvim-config/lua/configs/lualine.lua

180 lines
4.4 KiB
Lua
Raw Normal View History

2022-02-28 03:11:17 +00:00
local M = {}
function M.config()
2023-01-10 18:21:09 +00:00
local status_lualine_ok, lualine = pcall(require, 'lualine')
2022-09-27 17:02:49 +00:00
if not status_lualine_ok then
return
end
2023-01-10 18:21:09 +00:00
local status_gitblame_ok, gitblame = pcall(require, 'gitblame')
2022-09-27 17:02:49 +00:00
if not status_gitblame_ok then
2022-02-28 03:11:17 +00:00
return
end
local scolors = {
fg = '#adb0b9',
fg_wash = '#808289',
bg = '#252526',
2022-02-28 03:11:17 +00:00
inset = '#569cd6',
2022-10-10 20:58:32 +00:00
working_dir = '#569cd6',
branch = '#dcdcaa',
filetype = '#c5a6c0',
filename = '#91bde1',
2022-02-28 03:11:17 +00:00
added = '#6a9955',
modified = '#db812e',
removed = '#f6635a',
error = '#f53226',
warn = '#eed94e',
info = '#569cd6',
2022-02-28 03:11:17 +00:00
treesitter = '#6a9955',
scroll = '#dcdcaa',
}
local conditions = {
2023-01-10 18:21:09 +00:00
buffer_not_empty = function()
return vim.fn.empty(vim.fn.expand('%:t')) ~= 1
2022-02-28 03:11:17 +00:00
end,
hide_in_width = function()
return vim.fn.winwidth(0) > 80
end,
check_git_workspace = function()
2023-01-10 18:21:09 +00:00
local filepath = vim.fn.expand('%:p:h')
local gitdir = vim.fn.finddir('.git', filepath .. ';')
2022-02-28 03:11:17 +00:00
return gitdir and #gitdir > 0 and #gitdir < #filepath
end,
}
local config = {
options = {
2023-01-10 18:21:09 +00:00
disabled_filetypes = { 'NvimTree', 'dashboard', 'Outline' },
component_separators = '',
section_separators = '',
2022-02-28 03:11:17 +00:00
theme = {
normal = { c = { fg = scolors.fg, bg = scolors.bg } },
inactive = { c = { fg = scolors.fg, bg = scolors.bg } },
},
},
sections = {
lualine_a = {},
lualine_b = {},
2022-09-27 16:53:03 +00:00
lualine_c = {
2022-10-10 20:58:32 +00:00
{ -- working dir
2023-01-10 18:21:09 +00:00
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 = '',
2022-10-06 03:48:07 +00:00
padding = { left = 2, right = 1 },
},
{ -- file name
2023-01-10 18:21:09 +00:00
'filename',
path = 1,
icon = '',
color = { fg = scolors.filename, gui = 'bold' },
padding = { left = 1, right = 1 },
},
-- { -- git branch
-- "branch",
-- icon = "",
-- color = { fg = scolors.branch, gui = "bold" },
-- padding = { left = 1, right = 1 },
-- },
2022-10-10 20:58:32 +00:00
{ -- filetype
2023-01-10 18:21:09 +00:00
'filetype',
2022-10-10 20:58:32 +00:00
colored = false,
2023-01-10 18:21:09 +00:00
color = { fg = scolors.filetype, gui = 'bold' },
2022-10-10 20:58:32 +00:00
cond = conditions.buffer_not_empty,
padding = { left = 1, right = 1 },
2022-10-10 16:32:55 +00:00
},
{ -- git diff
2023-01-10 18:21:09 +00:00
'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
2023-01-10 18:21:09 +00:00
'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 },
},
2022-10-06 04:18:15 +00:00
padding = { left = 1, right = 1 },
},
},
2022-09-27 16:53:03 +00:00
lualine_x = {
{ -- git blame
2023-01-10 18:21:09 +00:00
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 },
},
{ -- location in file (line:col)
2023-01-10 18:21:09 +00:00
'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
2023-01-10 18:21:09 +00:00
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,
2023-01-10 18:21:09 +00:00
'progress',
color = { gui = 'none' },
padding = { left = 0, right = 1 },
},
},
2022-02-28 03:11:17 +00:00
lualine_y = {},
lualine_z = {},
},
inactive_sections = {
2022-10-10 20:58:32 +00:00
lualine_a = {
2022-10-06 03:48:07 +00:00
{ -- file name
2023-01-10 18:21:09 +00:00
'filename',
path = 1,
icon = '',
color = { fg = scolors.filename, gui = 'bold' },
2022-10-06 03:48:07 +00:00
padding = { left = 1, right = 1 },
},
2023-01-10 18:21:09 +00:00
},
2022-10-10 20:58:32 +00:00
lualine_b = {},
lualine_c = {},
lualine_x = {},
2022-09-27 16:53:03 +00:00
lualine_y = {},
lualine_z = {},
2023-01-10 18:21:09 +00:00
},
2022-02-28 03:11:17 +00:00
}
lualine.setup(config)
end
return M