local M = {} local config = { bg = "#202020", fg = "#ffffff", separator = " │ ", } local mode_names = { ["n"] = "NORMAL", ["no"] = "NORMAL", ["nov"] = "NORMAL", ["noV"] = "NORMAL", ["no\22"] = "NORMAL", ["niI"] = "NORMAL", ["niR"] = "NORMAL", ["niV"] = "NORMAL", ["i"] = "INSERT", ["ic"] = "INSERT", ["ix"] = "INSERT", ["v"] = "VISUAL", ["V"] = "V-LINE", ["\22"] = "V-BLOCK", ["s"] = "SELECT", ["S"] = "S-LINE", ["\19"] = "S-BLOCK", ["R"] = "REPLACE", ["Rc"] = "REPLACE", ["Rv"] = "V-REPLACE", ["c"] = "COMMAND", ["cv"] = "COMMAND", ["ce"] = "COMMAND", ["r"] = "PROMPT", ["rm"] = "MORE", ["r?"] = "CONFIRM", ["!"] = "SHELL", ["t"] = "TERMINAL", } local function mode() return mode_names[vim.fn.mode()] or "UNKNOWN" end local function filename() local name = vim.fn.expand("%:t") if name == "" then return "[No Name]" end return name end local function git_branch() local branch = vim.b.gitsigns_head if branch and branch ~= "" then return " " .. branch end return "" end local function filetype() if vim.bo.filetype == "" then return "text" end return vim.bo.filetype end local function active_lsp() local clients = vim.lsp.get_clients({ bufnr = 0, }) if #clients == 0 then return "-" end local names = {} for _, client in ipairs(clients) do table.insert(names, client.name) end return table.concat(names, ",") end local function diagnostics() local errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR, }) if errors > 0 then return "%#StatusError#●%*" end local warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN, }) if warnings > 0 then return "%#StatusWarn#●%*" end return "%#StatusNormal#●%*" end local function position() return string.format("%d:%d", vim.fn.line("."), vim.fn.col(".")) end local function build() local left = table.concat({ " ", mode(), config.separator, diagnostics(), config.separator, filename(), }) local right = {} local branch = git_branch() if branch ~= "" then table.insert(right, branch) end table.insert(right, filetype()) table.insert(right, active_lsp()) table.insert(right, position()) return left .. "%=" .. " " .. table.concat(right, config.separator) .. " " end function M.setup(opts) config = vim.tbl_extend("force", config, opts or {}) vim.api.nvim_set_hl(0, "StatusLine", { fg = config.fg, bg = config.bg, }) vim.api.nvim_set_hl(0, "StatusLineNC", { fg = config.fg, bg = config.bg, }) vim.api.nvim_set_hl(0, "StatusNormal", { fg = "#808080", bg = config.bg, }) vim.api.nvim_set_hl(0, "StatusLsp", { fg = "#61afef", bg = config.bg, }) vim.api.nvim_set_hl(0, "StatusWarn", { fg = "#e5c07b", bg = config.bg, }) vim.api.nvim_set_hl(0, "StatusError", { fg = "#e06c75", bg = config.bg, }) _G.StatusBar = build vim.o.statusline = "%!v:lua.StatusBar()" end return M