aboutsummaryrefslogtreecommitdiff
path: root/nvim/lua/config/statusline.lua
diff options
context:
space:
mode:
Diffstat (limited to 'nvim/lua/config/statusline.lua')
-rw-r--r--nvim/lua/config/statusline.lua364
1 files changed, 182 insertions, 182 deletions
diff --git a/nvim/lua/config/statusline.lua b/nvim/lua/config/statusline.lua
index 8a9c75a..3a6f1c7 100644
--- a/nvim/lua/config/statusline.lua
+++ b/nvim/lua/config/statusline.lua
@@ -1,182 +1,182 @@
1local M = {} 1local M = {}
2 2
3local modes = { 3local modes = {
4 n = { "NORMAL", "StatuslineModeNormal" }, 4 n = { "NORMAL", "StatuslineModeNormal" },
5 i = { "INSERT", "StatuslineModeInsert" }, 5 i = { "INSERT", "StatuslineModeInsert" },
6 v = { "VISUAL", "StatuslineModeVisual" }, 6 v = { "VISUAL", "StatuslineModeVisual" },
7 V = { "V-LINE", "StatuslineModeVisual" }, 7 V = { "V-LINE", "StatuslineModeVisual" },
8 [""] = { "V-BLOCK", "StatuslineModeVisual" }, 8 [""] = { "V-BLOCK", "StatuslineModeVisual" },
9 R = { "REPLACE", "StatuslineModeReplace" }, 9 R = { "REPLACE", "StatuslineModeReplace" },
10 c = { "COMMAND", "StatuslineModeCommand" }, 10 c = { "COMMAND", "StatuslineModeCommand" },
11} 11}
12 12
13local function mode() 13local function mode()
14 local m = vim.fn.mode() 14 local m = vim.fn.mode()
15 local entry = modes[m] or { m, "StatusLine" } 15 local entry = modes[m] or { m, "StatusLine" }
16 return string.format("%%#%s# %s %%#StatusLine#", entry[2], entry[1]) 16 return string.format("%%#%s# %s %%#StatusLine#", entry[2], entry[1])
17end 17end
18 18
19---------------------------------------------------------------------- 19----------------------------------------------------------------------
20-- Git branch (buffer-lokal, gecached, kein redraw-spam) 20-- Git branch (buffer-lokal, gecached, kein redraw-spam)
21---------------------------------------------------------------------- 21----------------------------------------------------------------------
22 22
23-- /dev/null gibt es unter Windows nicht (cmd.exe versteht das nicht als 23-- /dev/null gibt es unter Windows nicht (cmd.exe versteht das nicht als
24-- Pfad und meldet "Das System kann den angegebenen Pfad nicht finden"). 24-- Pfad und meldet "Das System kann den angegebenen Pfad nicht finden").
25local devnull = vim.fn.has("win32") == 1 and "NUL" or "/dev/null" 25local devnull = vim.fn.has("win32") == 1 and "NUL" or "/dev/null"
26 26
27local function update_git_branch(bufnr) 27local function update_git_branch(bufnr)
28 bufnr = bufnr or 0 28 bufnr = bufnr or 0
29 29
30 -- nur in echten Dateien 30 -- nur in echten Dateien
31 if vim.bo[bufnr].buftype ~= "" then 31 if vim.bo[bufnr].buftype ~= "" then
32 vim.b[bufnr].git_branch = "" 32 vim.b[bufnr].git_branch = ""
33 return 33 return
34 end 34 end
35 35
36 -- kein Git → nichts tun 36 -- kein Git → nichts tun
37 if vim.fn.executable("git") ~= 1 then 37 if vim.fn.executable("git") ~= 1 then
38 vim.b[bufnr].git_branch = "" 38 vim.b[bufnr].git_branch = ""
39 return 39 return
40 end 40 end
41 41
42 local branch = vim.fn.systemlist("git rev-parse --abbrev-ref HEAD 2>" .. devnull)[1] 42 local branch = vim.fn.systemlist("git rev-parse --abbrev-ref HEAD 2>" .. devnull)[1]
43 if branch then 43 if branch then
44 -- unter Windows bleibt an systemlist()-Zeilen mitunter ein 44 -- unter Windows bleibt an systemlist()-Zeilen mitunter ein
45 -- trailing \r haengen (^M in der Statuszeile sichtbar) 45 -- trailing \r haengen (^M in der Statuszeile sichtbar)
46 branch = branch:gsub("\r$", "") 46 branch = branch:gsub("\r$", "")
47 end 47 end
48 48
49 if branch and branch ~= "" then 49 if branch and branch ~= "" then
50 vim.b[bufnr].git_branch = "  " .. branch .. " " 50 vim.b[bufnr].git_branch = "  " .. branch .. " "
51 else 51 else
52 vim.b[bufnr].git_branch = "" 52 vim.b[bufnr].git_branch = ""
53 end 53 end
54end 54end
55 55
56---------------------------------------------------------------------- 56----------------------------------------------------------------------
57-- Autocmd: Git nur bei Bedarf aktualisieren 57-- Autocmd: Git nur bei Bedarf aktualisieren
58---------------------------------------------------------------------- 58----------------------------------------------------------------------
59 59
60vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained" }, { 60vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained" }, {
61 callback = function(args) 61 callback = function(args)
62 update_git_branch(args.buf) 62 update_git_branch(args.buf)
63 end, 63 end,
64}) 64})
65 65
66---------------------------------------------------------------------- 66----------------------------------------------------------------------
67-- Statusline-Sektionen (reine Darstellung, keine IO) 67-- Statusline-Sektionen (reine Darstellung, keine IO)
68---------------------------------------------------------------------- 68----------------------------------------------------------------------
69 69
70-- Git-Branch (buffer-lokal, gecached, kein redraw-spam) 70-- Git-Branch (buffer-lokal, gecached, kein redraw-spam)
71 71
72local function git() 72local function git()
73 return vim.b.git_branch or "" 73 return vim.b.git_branch or ""
74end 74end
75 75
76-- Git-Diff (buffer-lokal, kein redraw-spam) 76-- Git-Diff (buffer-lokal, kein redraw-spam)
77 77
78local function git_diff() 78local function git_diff()
79 local gsd = vim.b.gitsigns_status_dict 79 local gsd = vim.b.gitsigns_status_dict
80 if not gsd then return "" end 80 if not gsd then return "" end
81 81
82 local parts = {} 82 local parts = {}
83 if gsd.added and gsd.added > 0 then table.insert(parts, "+" .. gsd.added) end 83 if gsd.added and gsd.added > 0 then table.insert(parts, "+" .. gsd.added) end
84 if gsd.changed and gsd.changed > 0 then table.insert(parts, "~" .. gsd.changed) end 84 if gsd.changed and gsd.changed > 0 then table.insert(parts, "~" .. gsd.changed) end
85 if gsd.removed and gsd.removed > 0 then table.insert(parts, "-" .. gsd.removed) end 85 if gsd.removed and gsd.removed > 0 then table.insert(parts, "-" .. gsd.removed) end
86 86
87 if #parts > 0 then return " " .. table.concat(parts, " ") .. " " end 87 if #parts > 0 then return " " .. table.concat(parts, " ") .. " " end
88 88
89 return "" 89 return ""
90end 90end
91 91
92---------------------------------------------------------------------- 92----------------------------------------------------------------------
93-- Dateiname mit Modifikationsstatus 93-- Dateiname mit Modifikationsstatus
94---------------------------------------------------------------------- 94----------------------------------------------------------------------
95 95
96local function filename() 96local function filename()
97 local name = vim.fn.expand("%:.") 97 local name = vim.fn.expand("%:.")
98 if name == "" then name = "[No Name]" end 98 if name == "" then name = "[No Name]" end
99 99
100 if vim.bo.modified then name = name .. " [+]" end 100 if vim.bo.modified then name = name .. " [+]" end
101 101
102 return " " .. name .. " " 102 return " " .. name .. " "
103end 103end
104 104
105------------------------------------------------------------------------ 105------------------------------------------------------------------------
106-- Treesitter-Aktivität (buffer-lokal, kein redraw-spam) 106-- Treesitter-Aktivität (buffer-lokal, kein redraw-spam)
107------------------------------------------------------------------------ 107------------------------------------------------------------------------
108 108
109local function treesitter() 109local function treesitter()
110 local ok = vim.treesitter.highlighter.active[vim.api.nvim_get_current_buf()] 110 local ok = vim.treesitter.highlighter.active[vim.api.nvim_get_current_buf()]
111 if ok then return " 🌳 " end 111 if ok then return " 🌳 " end
112 return "" 112 return ""
113end 113end
114 114
115------------------------------------------------------------------------ 115------------------------------------------------------------------------
116-- Diagnostik-Counts (buffer-lokal, kein redraw-spam) 116-- Diagnostik-Counts (buffer-lokal, kein redraw-spam)
117------------------------------------------------------------------------ 117------------------------------------------------------------------------
118 118
119local function diagnostics() 119local function diagnostics()
120 local counts = { 120 local counts = {
121 error = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }), 121 error = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }),
122 warn = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }), 122 warn = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }),
123 info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }), 123 info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }),
124 hint = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }), 124 hint = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }),
125 } 125 }
126 126
127 local parts = {} 127 local parts = {}
128 128
129 if counts.error > 0 then table.insert(parts, "  " .. counts.error) end 129 if counts.error > 0 then table.insert(parts, "  " .. counts.error) end
130 if counts.warn > 0 then table.insert(parts, "  " .. counts.warn) end 130 if counts.warn > 0 then table.insert(parts, "  " .. counts.warn) end
131 if counts.info > 0 then table.insert(parts, "  " .. counts.info) end 131 if counts.info > 0 then table.insert(parts, "  " .. counts.info) end
132 if counts.hint > 0 then table.insert(parts, "  " .. counts.hint) end 132 if counts.hint > 0 then table.insert(parts, "  " .. counts.hint) end
133 133
134 if #parts > 0 then return " " .. table.concat(parts, " ") .. " " end 134 if #parts > 0 then return " " .. table.concat(parts, " ") .. " " end
135 135
136 return "" 136 return ""
137end 137end
138 138
139------------------------------------------------------------------------ 139------------------------------------------------------------------------
140-- Filetype & Encoding (buffer-lokal, kein redraw-spam) 140-- Filetype & Encoding (buffer-lokal, kein redraw-spam)
141------------------------------------------------------------------------ 141------------------------------------------------------------------------
142 142
143local function fileinfo() 143local function fileinfo()
144 local ft = vim.bo.filetype ~= "" and vim.bo.filetype or "none" 144 local ft = vim.bo.filetype ~= "" and vim.bo.filetype or "none"
145 local enc = vim.bo.fileencoding ~= "" and vim.bo.fileencoding or vim.o.encoding 145 local enc = vim.bo.fileencoding ~= "" and vim.bo.fileencoding or vim.o.encoding
146 return string.format(" %s %s ", ft, enc) 146 return string.format(" %s %s ", ft, enc)
147end 147end
148 148
149------------------------------------------------------------------------ 149------------------------------------------------------------------------
150-- Cursor-Position (kein redraw-spam) 150-- Cursor-Position (kein redraw-spam)
151------------------------------------------------------------------------ 151------------------------------------------------------------------------
152 152
153local function position() 153local function position()
154 return string.format(" %d:%d ", vim.fn.line("."), vim.fn.col(".")) 154 return string.format(" %d:%d ", vim.fn.line("."), vim.fn.col("."))
155end 155end
156 156
157---------------------------------------------------------------------- 157----------------------------------------------------------------------
158-- Öffentliche Statusline-Funktion 158-- Öffentliche Statusline-Funktion
159---------------------------------------------------------------------- 159----------------------------------------------------------------------
160 160
161function M.statusline() 161function M.statusline()
162 return table.concat({ 162 return table.concat({
163 -- LEFT: Mode & Context 163 -- LEFT: Mode & Context
164 mode(), 164 mode(),
165 "%#PmenuSel#", 165 "%#PmenuSel#",
166 git(), 166 git(),
167 git_diff(), 167 git_diff(),
168 "%#StatusLine#", 168 "%#StatusLine#",
169 filename(), 169 filename(),
170 170
171 "%=", 171 "%=",
172 172
173 -- RIGHT: Feedback & Meta 173 -- RIGHT: Feedback & Meta
174 diagnostics(), 174 diagnostics(),
175 treesitter(), 175 treesitter(),
176 fileinfo(), 176 fileinfo(),
177 " %p%% ", 177 " %p%% ",
178 position(), 178 position(),
179 }) 179 })
180end 180end
181 181
182return M 182return M