+/config

my dotfiles and nix configuration

git clone https://git.julia.blue/+/config

Julia RyanAdd melee-quick-mod0a0d15f

main
2.5 KiB75 linesraw
1local icons = { Hint = "", Info = "", Warn = "", Error = "" }
2local ls = vim.diagnostic.severity
3local sev = { Hint = ls.HINT, Info = ls.INFO, Warn = ls.WARN, Error = ls.ERROR }
4
5for k, v in pairs(icons) do
6    vim.fn.sign_define("DiagnosticSign" .. k, { text = v, texthl = "DiagnosticSign" .. k })
7end
8
9local function readonly() return (vim.o.readonly or not vim.o.modifiable) and "🔒" or "" end
10
11local function diagnostics()
12    local levels = {
13        Hint = "%%#DiagnosticSignHint#",
14        Info = "%%#DiagnosticSignInfo#",
15        Warn = "%%#DiagnosticSignWarn#",
16        Error = "%%#DiagnosticSignError#",
17    }
18    local t = {}
19    for l, s in pairs(levels) do
20        local n = #vim.diagnostic.get(0, { severity = sev[l] })
21        if n > 0 then t[#t + 1] = string.format(s .. " %s %s ", icons[l], n) end
22    end
23    return table.concat(t)
24end
25
26local function git()
27    local status = vim.b.gitsigns_status_dict ---@diagnostic disable-line: undefined-field
28    if not status then return "" end
29    local t, add, change, del = {}, status.added, status.changed, status.removed
30    if add and add > 0 then t[#t + 1] = "%#GitSignsAdd#+" .. add end
31    if change and change > 0 then t[#t + 1] = "%#GitSignsChange#+" .. change end
32    if del and del > 0 then t[#t + 1] = "%#GitSignsDelete#+" .. del end
33    if not t then return "" end
34    return "%#SignColumn# " .. table.concat(t, " ") .. " "
35end
36
37local function modified() return vim.o.modified and "%#StatusLineModified#" or "%#MoreMsg#" end
38
39vim.opt.showmode = false
40-- stylua: ignore
41local modes = {
42    i = "Insert", s = "Select", c = "Command", t = "Terminal",
43    v = "Visual", V = "Visual (line)", [""] = "Visual (block)",
44}
45local function mode()
46    local m = vim.api.nvim_get_mode().mode
47    if m == "n" then return "" end
48    return " " .. (modes[m] ~= nil and modes[m] or m)
49end
50
51local line_col = " %l:%-2c "
52local file = " %f "
53local fill = "%="
54local reset = "%*"
55
56StatusLine = {
57    active = function()
58        -- stylua: ignore
59        return table.concat {
60            readonly(), file, git(), modified(), mode(),
61            fill, diagnostics(), reset, line_col,
62        }
63    end,
64    inactive = function() return table.concat { file, fill, line_col } end,
65}
66
67local status = vim.api.nvim_create_augroup("StatusLine", {})
68vim.api.nvim_create_autocmd({ "WinEnter", "BufEnter" }, {
69    group = status,
70    command = "setlocal statusline=%!v:lua.StatusLine.active()",
71})
72vim.api.nvim_create_autocmd({ "WinLeave", "BufLeave" }, {
73    group = status,
74    command = "setlocal statusline=%!v:lua.StatusLine.inactive()",
75})