diff options
| author | Thomas Schmucker <ts@its1.de> | 2026-08-12 09:19:03 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2026-08-12 09:19:03 +0200 |
| commit | 6e5882a2fd02d30206ab9ca8aa5847b8ea09196c (patch) | |
| tree | 75d3b91f9005e51b93a37b44f3ad23ce4f48bc35 /nvim/lua/config/statusline.lua | |
| parent | 41c676453cd32fac760ff26e092c9dc81874739f (diff) | |
| download | dotfiles-6e5882a2fd02d30206ab9ca8aa5847b8ea09196c.tar.gz dotfiles-6e5882a2fd02d30206ab9ca8aa5847b8ea09196c.tar.bz2 dotfiles-6e5882a2fd02d30206ab9ca8aa5847b8ea09196c.zip | |
Normalize line endings
Diffstat (limited to 'nvim/lua/config/statusline.lua')
| -rw-r--r-- | nvim/lua/config/statusline.lua | 364 |
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 @@ | |||
| 1 | local M = {} | 1 | local M = {} |
| 2 | 2 | ||
| 3 | local modes = { | 3 | local 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 | ||
| 13 | local function mode() | 13 | local 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]) |
| 17 | end | 17 | end |
| 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"). |
| 25 | local devnull = vim.fn.has("win32") == 1 and "NUL" or "/dev/null" | 25 | local devnull = vim.fn.has("win32") == 1 and "NUL" or "/dev/null" |
| 26 | 26 | ||
| 27 | local function update_git_branch(bufnr) | 27 | local 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 |
| 54 | end | 54 | end |
| 55 | 55 | ||
| 56 | ---------------------------------------------------------------------- | 56 | ---------------------------------------------------------------------- |
| 57 | -- Autocmd: Git nur bei Bedarf aktualisieren | 57 | -- Autocmd: Git nur bei Bedarf aktualisieren |
| 58 | ---------------------------------------------------------------------- | 58 | ---------------------------------------------------------------------- |
| 59 | 59 | ||
| 60 | vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained" }, { | 60 | vim.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 | ||
| 72 | local function git() | 72 | local function git() |
| 73 | return vim.b.git_branch or "" | 73 | return vim.b.git_branch or "" |
| 74 | end | 74 | end |
| 75 | 75 | ||
| 76 | -- Git-Diff (buffer-lokal, kein redraw-spam) | 76 | -- Git-Diff (buffer-lokal, kein redraw-spam) |
| 77 | 77 | ||
| 78 | local function git_diff() | 78 | local 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 "" |
| 90 | end | 90 | end |
| 91 | 91 | ||
| 92 | ---------------------------------------------------------------------- | 92 | ---------------------------------------------------------------------- |
| 93 | -- Dateiname mit Modifikationsstatus | 93 | -- Dateiname mit Modifikationsstatus |
| 94 | ---------------------------------------------------------------------- | 94 | ---------------------------------------------------------------------- |
| 95 | 95 | ||
| 96 | local function filename() | 96 | local 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 .. " " |
| 103 | end | 103 | end |
| 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 | ||
| 109 | local function treesitter() | 109 | local 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 "" |
| 113 | end | 113 | end |
| 114 | 114 | ||
| 115 | ------------------------------------------------------------------------ | 115 | ------------------------------------------------------------------------ |
| 116 | -- Diagnostik-Counts (buffer-lokal, kein redraw-spam) | 116 | -- Diagnostik-Counts (buffer-lokal, kein redraw-spam) |
| 117 | ------------------------------------------------------------------------ | 117 | ------------------------------------------------------------------------ |
| 118 | 118 | ||
| 119 | local function diagnostics() | 119 | local 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 "" |
| 137 | end | 137 | end |
| 138 | 138 | ||
| 139 | ------------------------------------------------------------------------ | 139 | ------------------------------------------------------------------------ |
| 140 | -- Filetype & Encoding (buffer-lokal, kein redraw-spam) | 140 | -- Filetype & Encoding (buffer-lokal, kein redraw-spam) |
| 141 | ------------------------------------------------------------------------ | 141 | ------------------------------------------------------------------------ |
| 142 | 142 | ||
| 143 | local function fileinfo() | 143 | local 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) |
| 147 | end | 147 | end |
| 148 | 148 | ||
| 149 | ------------------------------------------------------------------------ | 149 | ------------------------------------------------------------------------ |
| 150 | -- Cursor-Position (kein redraw-spam) | 150 | -- Cursor-Position (kein redraw-spam) |
| 151 | ------------------------------------------------------------------------ | 151 | ------------------------------------------------------------------------ |
| 152 | 152 | ||
| 153 | local function position() | 153 | local 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(".")) |
| 155 | end | 155 | end |
| 156 | 156 | ||
| 157 | ---------------------------------------------------------------------- | 157 | ---------------------------------------------------------------------- |
| 158 | -- Öffentliche Statusline-Funktion | 158 | -- Öffentliche Statusline-Funktion |
| 159 | ---------------------------------------------------------------------- | 159 | ---------------------------------------------------------------------- |
| 160 | 160 | ||
| 161 | function M.statusline() | 161 | function 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 | }) |
| 180 | end | 180 | end |
| 181 | 181 | ||
| 182 | return M | 182 | return M |
