1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

update lualine config

- rearrange a few components
- add and remove a few components
This commit is contained in:
jdhao 2024-08-02 00:22:04 +02:00
parent 9efadac8fb
commit bbb8545403

View File

@ -99,12 +99,12 @@ end
local virtual_env = function() local virtual_env = function()
-- only show virtual env for Python -- only show virtual env for Python
if vim.bo.filetype ~= 'python' then if vim.bo.filetype ~= "python" then
return "" return ""
end end
local conda_env = os.getenv('CONDA_DEFAULT_ENV') local conda_env = os.getenv("CONDA_DEFAULT_ENV")
local venv_path = os.getenv('VIRTUAL_ENV') local venv_path = os.getenv("VIRTUAL_ENV")
if venv_path == nil then if venv_path == nil then
if conda_env == nil then if conda_env == nil then
@ -113,17 +113,32 @@ local virtual_env = function()
return string.format(" %s (conda)", conda_env) return string.format(" %s (conda)", conda_env)
end end
else else
local venv_name = vim.fn.fnamemodify(venv_path, ':t') local venv_name = vim.fn.fnamemodify(venv_path, ":t")
return string.format(" %s (venv)", venv_name) return string.format(" %s (venv)", venv_name)
end end
end end
local get_active_lsp = function()
local msg = "No Active Lsp"
local buf_ft = vim.api.nvim_get_option_value("filetype", {})
local clients = vim.lsp.get_clients { bufnr = 0 }
if next(clients) == nil then
return msg
end
for _, client in ipairs(clients) do
local filetypes = client.config.filetypes
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
return client.name
end
end
return msg
end
require("lualine").setup { require("lualine").setup {
options = { options = {
icons_enabled = true, icons_enabled = true,
theme = "auto", theme = "auto",
-- component_separators = { left = "", right = "" },
-- section_separators = { left = "", right = "" },
section_separators = "", section_separators = "",
component_separators = "", component_separators = "",
disabled_filetypes = {}, disabled_filetypes = {},
@ -132,18 +147,29 @@ require("lualine").setup {
sections = { sections = {
lualine_a = { "mode" }, lualine_a = { "mode" },
lualine_b = { lualine_b = {
"branch", {
"branch",
fmt = function(name, context)
-- truncate branch name in case the name is too long
return string.sub(name, 1, 20)
end,
},
{
virtual_env,
color = { fg = "black", bg = "#F1CA81" },
},
},
lualine_c = {
{
"filename",
symbols = {
readonly = "[🔒]",
},
},
{ {
"diff", "diff",
source = diff, source = diff,
}, },
{
virtual_env,
color = { fg = 'black', bg = "#F1CA81" }
}
},
lualine_c = {
"filename",
{ {
ime_state, ime_state,
color = { fg = "black", bg = "#f46868" }, color = { fg = "black", bg = "#f46868" },
@ -152,13 +178,19 @@ require("lualine").setup {
spell, spell,
color = { fg = "black", bg = "#a7c080" }, color = { fg = "black", bg = "#a7c080" },
}, },
},
lualine_x = {
{
get_active_lsp,
icon = " LSP:",
},
{ {
"diagnostics", "diagnostics",
sources = { "nvim_diagnostic" }, sources = { "nvim_diagnostic" },
symbols = {error = '🆇 ', warn = '⚠️ ', info = ' ', hint = ''}, symbols = { error = "🆇 ", warn = "⚠️ ", info = " ", hint = "" },
}, },
}, },
lualine_x = { lualine_y = {
"encoding", "encoding",
{ {
"fileformat", "fileformat",
@ -170,9 +202,6 @@ require("lualine").setup {
}, },
"filetype", "filetype",
}, },
lualine_y = {
"location",
},
lualine_z = { lualine_z = {
{ {
trailing_space, trailing_space,
@ -182,6 +211,7 @@ require("lualine").setup {
mixed_indent, mixed_indent,
color = "WarningMsg", color = "WarningMsg",
}, },
"progress"
}, },
}, },
inactive_sections = { inactive_sections = {