-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathlualine.lua
561 lines (522 loc) Β· 15 KB
/
lualine.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
local M = {}
local kind = require "user.lsp_kind"
local function clock()
return kind.icons.clock .. os.date "%H:%M"
end
local function diff_source()
local gitsigns = vim.b.gitsigns_status_dict
if gitsigns then
return {
added = gitsigns.added,
modified = gitsigns.changed,
removed = gitsigns.removed,
}
end
end
local function testing()
if vim.g.testing_status == "running" then
return "ο "
end
if vim.g.testing_status == "fail" then
return "οͺ"
end
if vim.g.testing_status == "pass" then
return "ο "
end
return nil
end
local mode = function()
local mod = vim.fn.mode()
local _time = os.date "*t"
local selector = math.floor(_time.hour / 8) + 1
local normal_icons = {
" σ° ",
" ο ",
" ο ",
}
if mod == "n" or mod == "no" or mod == "nov" then
return normal_icons[selector]
elseif mod == "i" or mod == "ic" or mod == "ix" then
local insert_icons = {
" ο¬ ",
" ο ",
" ο ",
}
return insert_icons[selector]
elseif mod == "V" or mod == "v" or mod == "vs" or mod == "Vs" or mod == "cv" then
local verbose_icons = {
" ο½ ",
" ξ« ",
" ο· ",
}
return verbose_icons[selector]
elseif mod == "c" or mod == "ce" then
local command_icons = {
" σ° ",
" ο ",
" ξ± ",
}
return command_icons[selector]
elseif mod == "r" or mod == "rm" or mod == "r?" or mod == "R" or mod == "Rc" or mod == "Rv" or mod == "Rv" then
local replace_icons = {
" ξ ",
" οΉ ",
" ξΈ ",
}
return replace_icons[selector]
end
return normal_icons[selector]
end
local file_icon_colors = {
Brown = "#905532",
Aqua = "#3AFFDB",
Blue = "#689FB6",
DarkBlue = "#44788E",
Purple = "#834F79",
Red = "#AE403F",
Beige = "#F5C06F",
Yellow = "#F09F17",
Orange = "#D4843E",
DarkOrange = "#F16529",
Pink = "#CB6F6F",
Salmon = "#EE6E73",
Green = "#8FAA54",
LightGreen = "#31B53E",
White = "#FFFFFF",
LightBlue = "#5fd7ff",
}
local function get_file_info()
return vim.fn.expand "%:t", vim.fn.expand "%:e"
end
local function get_file_icon()
local icon
local ok, devicons = pcall(require, "nvim-web-devicons")
if not ok then
print "No icon plugin found. Please install 'kyazdani42/nvim-web-devicons'"
return ""
end
local f_name, f_extension = get_file_info()
icon = devicons.get_icon(f_name, f_extension)
if icon == nil then
icon = kind.icons.question
end
return icon
end
local function get_file_icon_color()
local f_name, f_ext = get_file_info()
local has_devicons, devicons = pcall(require, "nvim-web-devicons")
if has_devicons then
local icon, iconhl = devicons.get_icon(f_name, f_ext)
if icon ~= nil then
return vim.fn.synIDattr(vim.fn.hlID(iconhl), "fg")
end
end
local icon = get_file_icon():match "%S+"
for k, _ in pairs(kind.file_icons) do
if vim.fn.index(kind.file_icons[k], icon) ~= -1 then
return file_icon_colors[k]
end
end
end
M.config = function()
local _time = os.date "*t"
local colors = require("user.theme").current_colors()
-- Color table for highlights
local mode_color = {
n = colors.git.delete,
i = colors.green,
v = colors.yellow,
[""] = colors.blue,
V = colors.yellow,
c = colors.cyan,
no = colors.magenta,
s = colors.orange,
S = colors.orange,
[""] = colors.orange,
ic = colors.yellow,
R = colors.violet,
Rv = colors.violet,
cv = colors.red,
ce = colors.red,
r = colors.cyan,
rm = colors.cyan,
["r?"] = colors.cyan,
["!"] = colors.red,
t = colors.red,
}
local conditions = {
buffer_not_empty = function()
return vim.fn.empty(vim.fn.expand "%:t") ~= 1
end,
hide_in_width = function()
return vim.o.columns > 80
end,
hide_small = function()
return vim.o.columns > 140
end,
check_git_workspace = function()
local filepath = vim.fn.expand "%:p:h"
local gitdir = vim.fn.finddir(".git", filepath .. ";")
return gitdir and #gitdir > 0 and #gitdir < #filepath
end,
}
-- Config
local config = {
options = {
icons_enabled = true,
-- Disable sections and component separators
component_separators = { left = "", right = "" },
section_separators = { left = "", right = "" },
theme = "auto",
disabled_filetypes = {
"dashboard",
"NvimTree",
"neo-tree",
"Outline",
"alpha",
"vista",
"vista_kind",
"TelescopePrompt",
},
always_divide_middle = true,
globalstatus = lvim.builtin.global_statusline and not lvim.builtin.tmux_lualine,
},
sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {},
lualine_x = {},
lualine_y = {},
lualine_z = {},
},
inactive_sections = {
-- these are to remove the defaults
lualine_a = {},
lualine_c = {
{
function()
local selector = math.floor(_time.hour / 8) + 1
local icns = {
" σ° ",
" ο ",
" ο ",
}
return icns[selector]
end,
color = function()
return { fg = mode_color[vim.fn.mode()], bg = colors.bg_alt }
end,
padding = { left = 1, right = 0 },
},
{
"filename",
cond = conditions.buffer_not_empty and conditions.hide_in_width,
color = { fg = colors.blue, gui = "bold" },
},
},
lualine_v = {},
lualine_x = {},
lualine_y = {},
lualine_z = {},
},
}
if lvim.builtin.global_statusline then
config.options.disabled_filetypes = { "alpha" }
end
-- Inserts a component in lualine_c at left section
local function ins_left(component)
table.insert(config.sections.lualine_c, component)
end
-- Inserts a component in lualine_x ot right section
local function ins_right(component)
table.insert(config.sections.lualine_x, component)
end
table.insert(config.sections.lualine_a, {
function()
return mode()
end,
color = function()
return { bg = mode_color[vim.fn.mode()], fg = colors.bg }
end,
})
table.insert(config.sections.lualine_b, {
"b:gitsigns_head",
icon = " ξ₯",
cond = conditions.check_git_workspace and conditions.hide_in_width,
color = { fg = colors.blue, bg = colors.bg },
padding = 0,
})
ins_left {
function()
local utils = require "lvim.core.lualine.utils"
local filename = vim.fn.expand "%:t"
local kube_env = vim.env.KUBECONFIG
local kube_filename = "kubectl-edit"
if (vim.bo.filetype == "yaml") and (string.sub(filename, 1, kube_filename:len()) == kube_filename) then
return string.format("β (%s)", utils.env_cleanup(kube_env))
end
return ""
end,
color = { fg = colors.cyan, bg = colors.bg },
cond = conditions.hide_small,
}
ins_left {
function()
vim.api.nvim_command(
"hi! LualineFileIconColor guifg=" .. get_file_icon_color() .. " guibg=" .. colors.bg .. " gui=bold"
)
local fname = vim.fn.expand "%:p"
if string.find(fname, "term://") ~= nil then
return kind.icons.term
end
local winnr = vim.api.nvim_win_get_number(vim.api.nvim_get_current_win())
if winnr > 10 then
winnr = 10
end
local win = kind.numbers[winnr]
return win .. " " .. get_file_icon()
end,
padding = { left = 2, right = 0 },
cond = conditions.buffer_not_empty and conditions.hide_small,
color = "LualineFileIconColor",
}
ins_left {
function()
local fname = vim.fn.expand "%:p"
local filename = vim.fn.expand "%:t"
local kube_filename = "kubectl-edit"
local ftype = vim.bo.filetype
local cwd = vim.api.nvim_call_function("getcwd", {})
if (vim.bo.filetype == "yaml") and (string.sub(filename, 1, kube_filename:len()) == kube_filename) then
return "kubernetes"
end
if (vim.fn.has "linux" == 1) or (vim.fn.has "mac" == 1) then
if string.find(fname, "zsh;#toggleterm") ~= nil then
return cwd
elseif string.find(fname, "lazygit;#toggleterm") ~= nil then
local git_repo_cmd = io.popen 'git remote get-url origin | tr -d "\n"'
local git_repo = git_repo_cmd:read "*a"
git_repo_cmd:close()
local git_branch_cmd = io.popen 'git branch --show-current | tr -d "\n"'
local git_branch = git_branch_cmd:read "*a"
git_branch_cmd:close()
return git_repo .. "~" .. git_branch
elseif #ftype < 1 and string.find(fname, "term") ~= nil then
return cwd
end
end
local show_name = vim.fn.expand "%:t"
if #cwd > 0 and #ftype > 0 then
show_name = fname:sub(#cwd + 2)
end
local readonly = ""
local modified = ""
if vim.bo.readonly then
readonly = " ξ©΅ "
end
if vim.bo.modified then
modified = " ο "
end
return show_name .. readonly .. modified
end,
cond = conditions.buffer_not_empty and conditions.hide_small,
padding = { left = 1, right = 1 },
color = { fg = colors.fg, gui = "bold", bg = colors.bg },
}
ins_left {
"diff",
source = diff_source,
symbols = { added = " οΎ ", modified = "ο ", removed = "ο
" },
diff_color = {
added = { fg = colors.git.add, bg = colors.bg },
modified = { fg = colors.git.change, bg = colors.bg },
removed = { fg = colors.git.delete, bg = colors.bg },
},
color = {},
cond = nil,
}
ins_left {
function()
local utils = require "lvim.core.lualine.utils"
if vim.bo.filetype == "python" then
local venv = vim.env.CONDA_DEFAULT_ENV
if venv then
return string.format(" ξ (%s)", utils.env_cleanup(venv))
end
venv = vim.env.VIRTUAL_ENV
if venv then
return string.format(" ξ (%s)", utils.env_cleanup(venv))
end
return ""
end
return ""
end,
color = { fg = colors.green },
cond = conditions.hide_in_width,
}
ins_left {
provider = function()
return testing()
end,
enabled = function()
return testing() ~= nil
end,
hl = {
fg = colors.fg,
},
left_sep = " ",
right_sep = {
str = " |",
hl = { fg = colors.fg },
},
}
ins_left {
function()
return "ξ΄"
end,
padding = { left = 0, right = 0 },
color = { fg = colors.bg },
cond = nil,
}
ins_right {
function()
return "ξΆ"
end,
padding = { left = 0, right = 0 },
color = { fg = colors.bg },
cond = nil,
}
ins_right {
"diagnostics",
sources = { "nvim_diagnostic" },
symbols = { error = kind.icons.error, warn = kind.icons.warn, info = kind.icons.info, hint = kind.icons.hint },
cond = conditions.hide_in_width,
color = { fg = colors.fg, bg = colors.bg },
}
ins_right {
function()
return "ο»"
end,
color = function()
local buf = vim.api.nvim_get_current_buf()
local ts = vim.treesitter.highlighter.active[buf]
return { fg = ts and not vim.tbl_isempty(ts) and colors.green or colors.red, bg = colors.bg }
end,
cond = conditions.hide_in_width,
}
ins_right {
function(msg)
msg = msg or kind.icons.ls_inactive .. "LS Inactive"
local buf_clients = vim.lsp.get_clients()
if next(buf_clients) == nil then
if type(msg) == "boolean" or #msg == 0 then
return kind.icons.ls_inactive .. "LS Inactive"
end
return msg
end
local buf_ft = vim.bo.filetype
local buf_client_names = {}
local only_lsp = ""
local lsp_icon = kind.icons.ls_active
for _, client in pairs(buf_clients) do
if client.name ~= "null-ls" then
local _added_client = client.name
only_lsp = only_lsp .. _added_client
_added_client = string.sub(client.name, 1, 7)
if client.name == "GitHub Copilot" then
lsp_icon = " "
else
table.insert(buf_client_names, _added_client)
end
end
end
-- add formatter
local formatters = require "lvim.lsp.null-ls.formatters"
local supported_formatters = {}
for _, fmt in pairs(formatters.list_registered(buf_ft)) do
local _added_formatter = fmt
_added_formatter = string.sub(fmt, 1, 4)
table.insert(supported_formatters, _added_formatter)
end
vim.list_extend(buf_client_names, supported_formatters)
-- add linter
local linters = require "lvim.lsp.null-ls.linters"
local supported_linters = {}
for _, lnt in pairs(linters.list_registered(buf_ft)) do
local _added_linter = lnt
_added_linter = string.sub(lnt, 1, 4)
table.insert(supported_linters, _added_linter)
end
vim.list_extend(buf_client_names, supported_linters)
if conditions.hide_small() then
return lsp_icon .. table.concat(buf_client_names, ", ")
elseif conditions.hide_in_width() then
return only_lsp
else
return string.sub(only_lsp, 1, 5)
end
end,
color = { fg = colors.fg, bg = colors.bg },
cond = conditions.hide_in_width,
}
ins_right {
"location",
padding = 0,
color = { fg = colors.orange, bg = colors.bg },
}
ins_right {
function()
local function format_file_size(file)
local size = vim.fn.getfsize(file)
if size <= 0 then
return ""
end
local sufixes = { "b", "k", "m", "g" }
local i = 1
while size > 1024 do
size = size / 1024
i = i + 1
end
return string.format("%.1f%s", size, sufixes[i])
end
local file = vim.fn.expand "%:p"
if string.len(file) == 0 then
return ""
end
return format_file_size(file)
end,
color = { fg = colors.fg, bg = colors.bg },
cond = conditions.buffer_not_empty and conditions.hide_small,
}
table.insert(config.sections.lualine_y, {
"fileformat",
fmt = string.upper,
icons_enabled = true,
color = { fg = colors.green, bg = colors.bg, gui = "bold" },
cond = conditions.hide_small,
})
table.insert(config.sections.lualine_y, {
clock,
cond = conditions.hide_small,
color = { fg = colors.blue, bg = colors.bg },
})
table.insert(config.sections.lualine_z, {
function()
local current_line = vim.fn.line "."
local total_lines = vim.fn.line "$"
local chars = { "__", "ββ", "ββ", "ββ", "ββ", "β
β
", "ββ", "ββ", "ββ" }
local line_ratio = current_line / total_lines
local index = math.ceil(line_ratio * #chars)
return chars[index]
end,
fmt = string.lower,
padding = 0,
color = { fg = colors.yellow, bg = colors.bg },
cond = nil,
})
-- Now don't forget to initialize lualine
lvim.builtin.lualine.options = config.options
lvim.builtin.lualine.sections = config.sections
lvim.builtin.lualine.inactive_sections = config.inactive_sections
end
return M