aboutsummaryrefslogtreecommitdiff
path: root/nvim/lua/config/statusline.lua
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2026-01-05 23:27:40 +0100
committerThomas Schmucker <ts@its1.de>2026-01-05 23:27:40 +0100
commit922518123990897e35ed1d94d0e6bd1314b7189e (patch)
tree98b23200b556c3ce22755488142590805e9ebb03 /nvim/lua/config/statusline.lua
parent10278b1d0111b7fb6941eaa8b7af0f88895b4535 (diff)
downloaddotfiles-922518123990897e35ed1d94d0e6bd1314b7189e.tar.gz
dotfiles-922518123990897e35ed1d94d0e6bd1314b7189e.tar.bz2
dotfiles-922518123990897e35ed1d94d0e6bd1314b7189e.zip
Neovim: Konfiguration für die Statusline hinzugefügt
Diffstat (limited to 'nvim/lua/config/statusline.lua')
-rw-r--r--nvim/lua/config/statusline.lua165
1 files changed, 165 insertions, 0 deletions
diff --git a/nvim/lua/config/statusline.lua b/nvim/lua/config/statusline.lua
new file mode 100644
index 0000000..fb89a66
--- /dev/null
+++ b/nvim/lua/config/statusline.lua
@@ -0,0 +1,165 @@
1local M = {}
2
3local modes = {
4 n = { "NORMAL", "StatuslineModeNormal" },
5 i = { "INSERT", "StatuslineModeInsert" },
6 v = { "VISUAL", "StatuslineModeVisual" },
7 V = { "V-LINE", "StatuslineModeVisual" },
8 [""] = { "V-BLOCK", "StatuslineModeVisual" },
9 R = { "REPLACE", "StatuslineModeReplace" },
10 c = { "COMMAND", "StatuslineModeCommand" },
11}
12
13local function mode()
14 local m = vim.fn.mode()
15 local entry = modes[m] or { m, "StatusLine" }
16 return string.format("%%#%s# %s %%#StatusLine#", entry[2], entry[1])
17end
18
19----------------------------------------------------------------------
20-- Git branch (buffer-lokal, gecached, kein redraw-spam)
21----------------------------------------------------------------------
22
23local function update_git_branch(bufnr)
24 bufnr = bufnr or 0
25
26 -- nur in echten Dateien
27 if vim.bo[bufnr].buftype ~= "" then
28 vim.b[bufnr].git_branch = ""
29 return
30 end
31
32 -- kein Git → nichts tun
33 if vim.fn.executable("git") ~= 1 then
34 vim.b[bufnr].git_branch = ""
35 return
36 end
37
38 local branch = vim.fn.systemlist(
39 "git rev-parse --abbrev-ref HEAD 2>/dev/null"
40 )[1]
41
42 if branch and branch ~= "" then
43 vim.b[bufnr].git_branch = "  " .. branch .. " "
44 else
45 vim.b[bufnr].git_branch = ""
46 end
47end
48
49----------------------------------------------------------------------
50-- Autocmd: Git nur bei Bedarf aktualisieren
51----------------------------------------------------------------------
52
53vim.api.nvim_create_autocmd(
54 { "BufEnter", "FocusGained" },
55 {
56 callback = function(args)
57 update_git_branch(args.buf)
58 end,
59 }
60)
61
62----------------------------------------------------------------------
63-- Statusline-Sektionen (reine Darstellung, keine IO)
64----------------------------------------------------------------------
65
66local function git()
67 return vim.b.git_branch or ""
68end
69
70local function git_diff()
71 local gsd = vim.b.gitsigns_status_dict
72 if not gsd then return "" end
73
74 local parts = {}
75 if gsd.added and gsd.added > 0 then table.insert(parts, "+" .. gsd.added) end
76 if gsd.changed and gsd.changed > 0 then table.insert(parts, "~" .. gsd.changed) end
77 if gsd.removed and gsd.removed > 0 then table.insert(parts, "-" .. gsd.removed) end
78
79 if #parts > 0 then
80 return " " .. table.concat(parts, " ") .. " "
81 end
82
83 return ""
84end
85
86local function filename()
87 local name = vim.fn.expand("%:t")
88 if name == "" then
89 name = "[No Name]"
90 end
91
92 if vim.bo.modified then
93 name = name .. " [+]"
94 end
95
96 return " " .. name .. " "
97end
98
99local function treesitter()
100 local ok = vim.treesitter.highlighter.active[vim.api.nvim_get_current_buf()]
101 if ok then
102 return " 🌳 "
103 end
104 return ""
105end
106
107local function diagnostics()
108 local counts = {
109 error = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }),
110 warn = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }),
111 info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }),
112 hint = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }),
113 }
114
115 local parts = {}
116
117 if counts.error > 0 then table.insert(parts, "  " .. counts.error) end
118 if counts.warn > 0 then table.insert(parts, "  " .. counts.warn) end
119 if counts.info > 0 then table.insert(parts, "  " .. counts.info) end
120 if counts.hint > 0 then table.insert(parts, "  " .. counts.hint) end
121
122 if #parts > 0 then
123 return " " .. table.concat(parts, " ") .. " "
124 end
125
126 return ""
127end
128
129local function fileinfo()
130 local ft = vim.bo.filetype ~= "" and vim.bo.filetype or "none"
131 local enc = vim.bo.fileencoding ~= "" and vim.bo.fileencoding or vim.o.encoding
132 return string.format(" %s %s ", ft, enc)
133end
134
135local function position()
136 return string.format(" %d:%d ", vim.fn.line("."), vim.fn.col("."))
137end
138
139----------------------------------------------------------------------
140-- Öffentliche Statusline-Funktion
141----------------------------------------------------------------------
142
143function M.statusline()
144 return table.concat({
145 -- LEFT: Mode & Context
146 mode(),
147 "%#PmenuSel#",
148 git(),
149 git_diff(),
150 "%#StatusLine#",
151 filename(),
152
153 "%=",
154
155 -- RIGHT: Feedback & Meta
156 diagnostics(),
157 treesitter(),
158 "%#StatusLineNC#",
159 fileinfo(),
160 " %p%% ",
161 position(),
162 })
163end
164
165return M