-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlualine.lua
622 lines (581 loc) · 16 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
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
local M = {}
local kind = require "user.lsp_kind"
local diag_source = "nvim_lsp"
local ok, _ = pcall(require, "vim.diagnostic")
if ok then
diag_source = "nvim"
end
local function clock()
return kind.icons.clock .. os.date "%H:%M"
end
local function lsp_progress()
local messages = vim.lsp.util.get_progress_messages()
if #messages == 0 then
return ""
end
local status = {}
for _, msg in pairs(messages) do
table.insert(status, (msg.percentage or 0) .. "%% " .. (msg.title or ""))
end
-- local spinners = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }
-- local spinners = { " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }
-- local spinners = { " ", " ", " ", " ", " ", " ", " ", " ", " " }
local spinners = {
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
}
local ms = vim.loop.hrtime() / 1000000
local frame = math.floor(ms / 120) % #spinners
return table.concat(status, " | ") .. " " .. spinners[frame + 1]
end
vim.cmd [[autocmd User LspProgressUpdate let &ro = &ro]]
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 function using_session()
return (vim.g.using_persistence ~= 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 _, 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
local default_colors = {
bg = "#202328",
bg_alt = "#202328",
fg = "#bbc2cf",
yellow = "#ECBE7B",
cyan = "#008080",
darkblue = "#081633",
green = "#98be65",
orange = "#FF8800",
violet = "#a9a1e1",
magenta = "#c678dd",
blue = "#51afef",
red = "#ec5f67",
git = { change = "#ECBE7B", add = "#98be65", delete = "#ec5f67", conflict = "#bb7a61" },
}
M.config = function()
local colors = default_colors
local themes = require("user.theme").colors
local _time = os.date "*t"
if _time.hour >= 5 and _time.hour < 8 then
colors = themes.zephyr_colors
elseif _time.hour >= 8 and _time.hour < 11 then
colors = themes.rose_pine_colors
elseif (_time.hour >= 0 and _time.hour < 5) or (_time.hour >= 11 and _time.hour < 17) then
colors = themes.tokyonight_colors
elseif _time.hour >= 17 and _time.hour < 21 then
colors = themes.doom_one_colors
elseif _time.hour >= 21 and _time.hour < 24 then
colors = themes.onedarker_colors
end
-- 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.fn.winwidth(0) > 80 or lvim.builtin.global_status_line.active
end,
hide_small = function()
return vim.fn.winwidth(0) > 150 or lvim.builtin.global_status_line.active
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 = {
-- We are going to use lualine_c an lualine_x as left and
-- right section. Both are highlighted by c theme . So we
-- are just setting default looks o statusline
normal = { c = { fg = colors.fg, bg = colors.bg } },
inactive = { c = { fg = colors.fg, bg = colors.bg_alt } },
},
disabled_filetypes = { "dashboard", "NvimTree", "Outline", "alpha" },
},
sections = {
-- these are to remove the defaults
lualine_a = {},
lualine_b = {},
lualine_y = {},
lualine_z = {},
-- These will be filled later
lualine_c = {},
lualine_x = {},
},
inactive_sections = {
-- these are to remove the defaults
lualine_a = {},
lualine_v = {},
lualine_y = {},
lualine_z = {},
lualine_c = {
{
function()
vim.api.nvim_command(
"hi! LualineModeInactive guifg=" .. mode_color[vim.fn.mode()] .. " guibg=" .. colors.bg_alt
)
local selector = math.floor(_time.hour / 8) + 1
local icns = {
" ",
" ",
" ",
}
return icns[selector]
-- return " "
-- return mode()
end,
color = "LualineModeInactive",
padding = { left = 1, right = 0 },
},
{
"filename",
cond = conditions.buffer_not_empty,
color = { fg = colors.blue, gui = "bold" },
},
},
lualine_x = {},
},
}
-- 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
ins_left {
function()
vim.api.nvim_command("hi! LualineMode guifg=" .. mode_color[vim.fn.mode()] .. " guibg=" .. colors.bg)
return mode()
end,
color = "LualineMode",
padding = { left = 1, right = 0 },
}
ins_left {
"b:gitsigns_head",
icon = " ",
cond = conditions.check_git_workspace,
color = { fg = colors.blue },
padding = 0,
}
ins_left {
function()
local utils = require "lvim.core.lualine.utils"
local filename = vim.fn.expand "%"
local kube_env = os.getenv "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 },
cond = conditions.hide_in_width,
}
ins_left {
function()
vim.api.nvim_command("hi! LualineFileIconColor guifg=" .. get_file_icon_color() .. " guibg=" .. colors.bg)
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,
color = "LualineFileIconColor",
gui = "bold",
}
ins_left {
function()
local fname = vim.fn.expand "%:p"
local ftype = vim.fn.expand "%:e"
local cwd = vim.api.nvim_call_function("getcwd", {})
local show_name = vim.fn.expand "%:t"
if #cwd > 0 and #ftype > 0 then
show_name = fname:sub(#cwd + 2)
end
return show_name .. "%{&readonly?' ':''}" .. "%{&modified?' ':''}"
end,
cond = conditions.buffer_not_empty,
padding = { left = 1, right = 1 },
color = { fg = colors.fg, gui = "bold" },
}
ins_left {
"diff",
source = diff_source,
symbols = { added = " ", modified = "柳", removed = " " },
diff_color = {
added = { fg = colors.git.add },
modified = { fg = colors.git.change },
removed = { fg = colors.git.delete },
},
color = {},
cond = nil,
}
ins_left {
function()
local utils = require "lvim.core.lualine.utils"
if vim.bo.filetype == "python" then
local venv = os.getenv "CONDA_DEFAULT_ENV"
if venv then
return string.format(" (%s)", utils.env_cleanup(venv))
end
venv = os.getenv "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 {
provider = function()
if vim.g.using_persistence then
return " |"
elseif vim.g.using_persistence == false then
return " |"
end
end,
enabled = function()
return using_session()
end,
hl = {
fg = colors.fg,
},
}
ins_left {
lsp_progress,
cond = conditions.hide_small,
}
-- Insert mid section. You can make any number of sections in neovim :)
-- for lualine it's any number greater then 2
ins_left {
function()
return "%="
end,
}
ins_right {
function()
if not vim.bo.readonly or not vim.bo.modifiable then
return ""
end
return "" -- """
end,
color = { fg = colors.red },
}
ins_right {
"diagnostics",
sources = { diag_source },
symbols = { error = kind.icons.error, warn = kind.icons.warn, info = kind.icons.info, hint = kind.icons.hint },
cond = conditions.hide_in_width,
}
ins_right {
function()
if next(vim.treesitter.highlighter.active) then
return " "
end
return ""
end,
padding = 0,
color = { fg = colors.green },
cond = conditions.hide_in_width,
}
ins_right {
function(msg)
msg = msg or kind.icons.ls_inactive .. "LS Inactive"
local buf_clients = vim.lsp.buf_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 trim = vim.fn.winwidth(0) < 120
if lvim.builtin.global_status_line.active then
trim = false
end
for _, client in pairs(buf_clients) do
if client.name ~= "null-ls" then
local _added_client = client.name
if trim then
_added_client = string.sub(client.name, 1, 4)
end
table.insert(buf_client_names, _added_client)
end
end
-- add formatter
local formatters = require "lvim.lsp.null-ls.formatters"
local supported_formatters = {}
for _, fmt in pairs(formatters.list_registered_providers(buf_ft)) do
local _added_formatter = fmt
if trim then
_added_formatter = string.sub(fmt, 1, 4)
end
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_providers(buf_ft)) do
local _added_linter = lnt
if trim then
_added_linter = string.sub(lnt, 1, 4)
end
table.insert(supported_linters, _added_linter)
end
vim.list_extend(buf_client_names, supported_linters)
return kind.icons.ls_active .. table.concat(buf_client_names, ", ")
end,
color = { fg = colors.fg },
cond = conditions.hide_in_width,
}
ins_right {
"location",
padding = 0,
color = { fg = colors.orange },
}
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,
cond = conditions.buffer_not_empty,
}
ins_right {
"fileformat",
fmt = string.upper,
icons_enabled = true,
color = { fg = colors.green, gui = "bold" },
cond = conditions.hide_in_width,
}
ins_right {
clock,
cond = conditions.hide_in_width,
color = { fg = colors.blue, bg = colors.bg },
}
ins_right {
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,
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