nvim-config/lua/configs/lualine.lua

218 lines
5.5 KiB
Lua
Raw Normal View History

2022-02-28 03:11:17 +00:00
local M = {}
function M.config()
2022-09-27 17:02:49 +00:00
local status_lualine_ok, lualine = pcall(require, "lualine")
if not status_lualine_ok then
return
end
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',
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 = {
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()
local filepath = vim.fn.expand "%:p:h"
local gitdir = vim.fn.finddir(".git", filepath .. ";")
return gitdir and #gitdir > 0 and #gitdir < #filepath
end,
}
local config = {
options = {
disabled_filetypes = { "NvimTree", "dashboard", "Outline" },
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 = {},
2022-09-27 16:53:03 +00:00
lualine_c = {
{ -- filetype
"filetype",
colored = false,
color = { fg = scolors.filetype, gui = "bold" },
cond = conditions.buffer_not_empty,
2022-10-06 03:48:07 +00:00
padding = { left = 2, right = 1 },
},
{ -- file name
"filename",
color = { fg = scolors.filename, gui = "bold" },
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 = 2, right = 1 },
},
2022-10-06 03:48:07 +00:00
{ -- git branch
"branch",
icon = "",
color = { fg = scolors.branch, gui = "bold" },
padding = { left = 1, right = 1 },
},
},
2022-09-27 16:53:03 +00:00
lualine_x = {
{ -- git blame
gitblame.get_current_blame_text,
color = { fg = scolors.fg_wash },
cond = gitblame.is_blame_text_available,
padding = { left = 0, 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 },
},
},
2022-02-28 03:11:17 +00:00
lualine_y = {},
lualine_z = {},
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
2022-10-06 03:48:07 +00:00
lualine_c = {
{ -- filetype
"filetype",
colored = false,
color = { fg = scolors.filetype, gui = "bold" },
cond = conditions.buffer_not_empty,
padding = { left = 2, right = 1 },
},
{ -- file name
"filename",
color = { fg = scolors.filename, gui = "bold" },
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 = 2, right = 1 },
},
{ -- git branch
"branch",
icon = "",
padding = { left = 1, right = 1 },
},
},
lualine_x = {
{ -- 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 },
},
},
2022-09-27 16:53:03 +00:00
lualine_y = {},
lualine_z = {},
2022-10-06 03:48:07 +00:00
}
2022-02-28 03:11:17 +00:00
}
lualine.setup(config)
end
return M