lualine.lua - dotfiles - đ personal arsenal of "rice"
HTML git clone https://git.drkhsh.at/dotfiles.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
lualine.lua (9221B)
---
1 return {
2 "nvim-lualine/lualine.nvim",
3 event = "VeryLazy",
4 dependencies = { "nvim-tree/nvim-web-devicons" },
5 init = function()
6 -- disable until lualine loads
7 vim.opt.laststatus = 0
8 end,
9 opts = function()
10 local miasma_colors = {
11 bg = "#222222",
12 black = "#222222",
13 magenta = "#bb7744",
14 green = "#222222",
15 lost = "#666666",
16 unit01 = "#bb7744",
17 selee = "#5f875f",
18 mint = "#C9A554",
19 hazard = "#B36D43",
20 purple = "#bb7744",
21 lcl = "#5f875f",
22 nerv = "#78824b",
23 rei = "#222222",
24 blood = "#685742",
25 }
26 local gruvbox_colors = {
27 bg = "#282828",
28 black = "#000000",
29 magenta = "#9d0006",
30 green = "#b8bb26",
31 lost = "#665c54",
32 unit01 = "#8f3f71",
33 selee = "#b16286",
34 mint = "#427b58",
35 hazard = "#fe8019",
36 purple = "#d3869b",
37 lcl = "#504945",
38 nerv = "#cc241d",
39 rei = "#32302f",
40 blood = "#fb4934",
41 }
42 -- evangelion colors
43 local evangelion_colors = {
44 bg = "#201430",
45 black = "#000000",
46 magenta = "#483160",
47 green = "#87FF5F",
48 lost = "#666666",
49 unit01 = "#67478a",
50 selee = "#875FAF",
51 mint = "#9cda7c",
52 hazard = "#D99145",
53 purple = "#AB92FC",
54 lcl = "#5b2b41",
55 nerv = "#bf2d2d",
56 rei = "#e1d6f8",
57 }
58 local colors = miasma_colors
59
60 local conditions = {
61 buffer_not_empty = function()
62 return vim.fn.empty(vim.fn.expand("%:t")) ~= 1
63 end,
64 hide_in_width_first = function()
65 return vim.fn.winwidth(0) > 80
66 end,
67 hide_in_width = function()
68 return vim.fn.winwidth(0) > 70
69 end,
70 check_git_workspace = function()
71 local filepath = vim.fn.expand("%:p:h")
72 local gitdir = vim.fn.finddir(".git", filepath .. ";")
73 return gitdir and #gitdir > 0 and #gitdir < #filepath
74 end,
75 }
76 -- auto change color according to neovims mode
77 local mode_color = {
78 n = { bg = colors.magenta, fg = colors.green },
79 i = { bg = colors.purple, fg = colors.black },
80 v = { bg = colors.green, fg = colors.black },
81 [""] = { bg = colors.green, fg = colors.black },
82 V = { bg = colors.green, fg = colors.black },
83 c = { bg = colors.hazard, fg = colors.black },
84 no = { bg = colors.green, fg = colors.black },
85 s = { bg = colors.hazard, fg = colors.black },
86 S = { bg = colors.hazard, fg = colors.black },
87 [""] = { bg = colors.hazard, fg = colors.black },
88 ic = { bg = colors.hazard, fg = colors.black },
89 R = { bg = colors.hazard, fg = colors.black },
90 Rv = { bg = colors.hazard, fg = colors.black },
91 cv = { bg = colors.hazard, fg = colors.black },
92 ce = { bg = colors.hazard, fg = colors.black },
93 r = { bg = colors.blood, fg = colors.black },
94 rm = { bg = colors.blood, fg = colors.black },
95 ["r?"] = { bg = colors.lcl, fg = colors.black },
96 ["!"] = { bg = colors.lcl, fg = colors.black },
97 t = { bg = colors.green, fg = colors.black },
98 }
99 -- config
100 local config = {
101 options = {
102 -- remove default sections and component separators
103 component_separators = "",
104 section_separators = "",
105 theme = {
106 -- setting defaults to statusline
107 normal = { c = { fg = colors.fg, bg = colors.bg } },
108 inactive = { c = { fg = colors.fg, bg = colors.bg } },
109 },
110 },
111 sections = {
112 -- clear defaults
113 lualine_a = {},
114 lualine_b = {},
115 lualine_y = {},
116 lualine_z = {},
117 -- clear for later use
118 lualine_c = {},
119 lualine_x = {},
120 },
121 inactive_sections = {
122 -- clear defaults
123 lualine_a = {},
124 lualine_b = {},
125 lualine_y = {},
126 lualine_z = {},
127 -- clear for later use
128 lualine_c = {},
129 lualine_x = {},
130 },
131 }
132
133 -- insert active component in lualine_c at left section
134 local function active_left(component)
135 table.insert(config.sections.lualine_c, component)
136 end
137
138 -- insert inactive component in lualine_c at left section
139 local function inactive_left(component)
140 table.insert(config.inactive_sections.lualine_c, component)
141 end
142
143 -- insert active component in lualine_x at right section
144 local function active_right(component)
145 table.insert(config.sections.lualine_x, component)
146 end
147
148 -- insert inactive component in lualine_x at right section
149 local function inactive_right(component)
150 table.insert(config.inactive_sections.lualine_x, component)
151 end
152
153 -- dump object contents
154 local function dump(o)
155 if type(o) == "table" then
156 local s = ""
157 for k, v in pairs(o) do
158 if type(k) ~= "number" then
159 k = '"' .. k .. '"'
160 end
161 s = s .. dump(v) .. ","
162 end
163 return s
164 else
165 return tostring(o)
166 end
167 end
168
169 -- active left section
170 active_left({
171 function()
172 local icon
173 local ok, devicons = pcall(require, "nvim-web-devicons")
174 if ok then
175 icon = devicons.get_icon(vim.fn.expand("%:t"))
176 if icon == nil then
177 icon = devicons.get_icon_by_filetype(vim.bo.filetype)
178 end
179 else
180 if vim.fn.exists("*WebDevIconsGetFileTypeSymbol") > 0 then
181 icon = vim.fn.WebDevIconsGetFileTypeSymbol()
182 end
183 end
184 if icon == nil then
185 icon = "î"
186 end
187 return icon:gsub("%s+", "")
188 end,
189 color = function()
190 return { bg = mode_color[vim.fn.mode()].bg, fg = mode_color[vim.fn.mode()].fg }
191 end,
192 padding = { left = 1, right = 1 },
193 separator = { right = "âââ" },
194 })
195 active_left({
196 "filename",
197 cond = conditions.buffer_not_empty,
198 color = function()
199 return { bg = mode_color[vim.fn.mode()].bg, fg = mode_color[vim.fn.mode()].fg }
200 end,
201 padding = { left = 1, right = 1 },
202 separator = { right = "âââ" },
203 symbols = {
204 modified = "ķ°ļģ ",
205 readonly = "īŖ ",
206 unnamed = "ī¨ ",
207 newfile = "ī§ ",
208 },
209 })
210 active_left({
211 "branch",
212 icon = "",
213 color = { bg = colors.selee, fg = colors.rei },
214 padding = { left = 0, right = 1 },
215 separator = { right = "âââ", left = "âââ" },
216 })
217
218 -- inactive left section
219 inactive_left({
220 function()
221 return "î"
222 end,
223 cond = conditions.buffer_not_empty,
224 color = { bg = colors.black, fg = colors.lost },
225 padding = { left = 1, right = 1 },
226 })
227 inactive_left({
228 "filename",
229 cond = conditions.buffer_not_empty,
230 color = { bg = colors.black, fg = colors.lost },
231 padding = { left = 1, right = 1 },
232 separator = { right = "âââ" },
233 symbols = {
234 modified = "",
235 readonly = "",
236 unnamed = "",
237 newfile = "",
238 },
239 })
240
241 -- active right section
242 active_right({
243 function()
244 if vim.lsp.get_clients then
245 local clients = vim.lsp.get_clients({ bufnr = 0 })
246 local clients_list = {}
247 for _, client in pairs(clients) do
248 if not clients_list[client.name] then
249 table.insert(clients_list, client.name)
250 end
251 end
252 local lsp_lbl = dump(clients_list):gsub("(.*),", "%1")
253 return lsp_lbl:gsub(",", ", ")
254 end
255 end,
256 icon = "ī
",
257 color = { bg = colors.mint, fg = colors.black },
258 padding = { left = 1, right = 1 },
259 cond = conditions.hide_in_width_first,
260 separator = { right = "âââ", left = "âââ" },
261 })
262
263 active_right({
264 "diagnostics",
265 sources = { "nvim_diagnostic" },
266 symbols = { error = "ī ", warn = "īą ", info = "īĒ " },
267 diagnostics_color = {
268 error = { fg = colors.black },
269 info = { fg = colors.black },
270 warn = { fg = colors.black },
271 },
272 colounit01 = false,
273 color = { bg = colors.hazard, fg = colors.black },
274 padding = { left = 1, right = 1 },
275 separator = { right = "âââ", left = "âââ" },
276 })
277 active_right({
278 "searchcount",
279 color = { bg = colors.purple, fg = colors.rei },
280 padding = { left = 1, right = 1 },
281 separator = { right = "âââ", left = "âââ" },
282 })
283 active_right({
284 "location",
285 color = { bg = colors.unit01, fg = colors.rei },
286 padding = { left = 1, right = 0 },
287 separator = { left = "âââ" },
288 })
289 active_right({
290 function()
291 local cur = vim.fn.line(".")
292 local total = vim.fn.line("$")
293 return string.format("%2d%%%%", math.floor(cur / total * 100))
294 end,
295 color = { bg = colors.unit01, fg = colors.rei },
296 padding = { left = 1, right = 1 },
297 cond = conditions.hide_in_width,
298 separator = { right = "âââ" },
299 })
300 active_right({
301 "o:encoding",
302 fmt = string.upper,
303 cond = conditions.hide_in_width,
304 padding = { left = 1, right = 1 },
305 color = { bg = colors.selee, fg = colors.black },
306 })
307 active_right({
308 "fileformat",
309 fmt = string.lower,
310 icons_enabled = false,
311 cond = conditions.hide_in_width,
312 color = { bg = colors.selee, fg = colors.black },
313 padding = { left = 0, right = 1 },
314 })
315
316 -- inactive right section
317 inactive_right({
318 "location",
319 color = { bg = colors.black, fg = colors.lost },
320 padding = { left = 1, right = 0 },
321 separator = { left = "âââ" },
322 })
323 inactive_right({
324 "progress",
325 color = { bg = colors.black, fg = colors.lost },
326 cond = conditions.hide_in_width,
327 padding = { left = 1, right = 1 },
328 separator = { right = "âââ" },
329 })
330 inactive_right({
331 "fileformat",
332 fmt = string.lower,
333 icons_enabled = false,
334 cond = conditions.hide_in_width,
335 color = { bg = colors.black, fg = colors.lost },
336 separator = { right = "âââ" },
337 padding = { left = 0, right = 1 },
338 })
339 --
340 return config
341 end,
342 }
343