2 -local icon
= require(
"std.icon")
3 -local auto
= require(
"std.auto")
4 -local ignored
= require(
"std.ignored")
6 -local NEW_FILE
= "~untitled~" 10 - "rebelot/heirline.nvim",
14 - "nvim-tree/nvim-web-devicons",
15 - {
"lewis6991/gitsigns.nvim",
lazy =
true },
16 - {
"SmiteshP/nvim-navic",
lazy =
true },
19 - local heirline
= require(
"heirline")
20 - local conditions
= require(
"heirline.conditions")
21 - local utils
= require(
"heirline.utils")
23 - local nugu
= require(
"bugabinga.nugu.palette")
24 - heirline.load_colors(nugu)
26 - auto(
"reload_heirline_colors")({
27 - description =
"Reload dark/light nugu colors for Heirline",
28 - events =
"ColorScheme",
29 - command =
function()
30 - utils.on_colorscheme(nugu)
35 - init =
function(self)
36 - self.mode
= vim.fn.mode(
1)
42 - no = icon.normal
.. "?",
43 - nov = icon.normal
.. "?",
44 - noV = icon.normal
.. "?",
45 - [
"no\22"] = icon.normal
.. "?",
46 - niI = icon.normal
.. "i",
47 - niR = icon.normal
.. "r",
48 - niV = icon.normal
.. "v",
49 - nt = icon.normal
.. "t",
51 - vs = icon.visual
.. "s",
52 - V = icon.visual
.. "_",
53 - Vs = icon.visual
.. "s",
54 - [
"\22"] =
"^" .. icon.visual,
55 - [
"\22s"] =
"^" .. icon.visual,
57 - S = icon.select
.. "_",
58 - [
"\19"] =
"^" .. icon.select,
60 - ic = icon.insert
.. "c",
61 - ix = icon.insert
.. "x",
63 - Rc = icon.replace
.. "c",
64 - Rx = icon.replace
.. "x",
65 - Rv = icon.replace
.. "v",
66 - Rvc = icon.replace
.. "v",
67 - Rvx = icon.replace
.. "v",
69 - cv = icon.command
.. "x",
71 - rm = icon.pending
.. "m",
72 - [
"r?"] = icon.pending
.. "?",
73 - [
"!"] = icon.exclaim,
79 - v =
"ui_important_global",
80 - V =
"ui_important_global",
81 - [
"\22"] =
"ui_important_global",
82 - c =
"ui_important_global",
83 - s =
"ui_important_global",
84 - S =
"ui_important_global",
85 - [
"\19"] =
"ui_important_global",
86 - R =
"ui_important_global",
87 - r =
"ui_important_global",
88 - [
"!"] =
"ui_important_global",
89 - t =
"ui_important_global",
93 - provider =
function(self)
94 - local mode_name
= self.mode_names[self.mode]
95 - return " " .. icon.vim
.. " %3(" .. mode_name
.. "%) " 99 - local mode
= self.mode:sub(
1,
1)
100 - return {
fg = self.mode_colors[mode],
bold =
true }
106 - callback = vim.schedule_wrap(
function()
107 - vim.cmd.redrawstatus()
112 - local file_icon
= {
113 - init =
function(self)
114 - local filename
= self.filename
115 - local extension
= vim.fn.fnamemodify(filename,
":e")
116 - self.icon
= require(
"nvim-web-devicons").get_icon_color(filename, extension, {
default =
true })
118 - provider =
function(self)
119 - return self.icon
and (self.icon
.. " ")
121 - hl =
"DefaultIcon",
124 - local file_name
= {
125 - init =
function(self)
126 - self.lfilename
= vim.fs.normalize(vim.fn.fnamemodify(self.filename,
":."))
127 - if self.lfilename
== "" then 128 - self.lfilename
= NEW_FILE
135 - provider =
function(self)
136 - return self.lfilename
140 - provider =
function(self)
141 - return vim.fs.normalize(vim.fn.pathshorten(self.lfilename))
146 - local file_flags
= {
148 - condition =
function()
149 - return vim.bo.modified
151 - provider =
string.
format(
" %s ", icon.modified),
155 - condition =
function()
156 - return not vim.bo.modifiable
or vim.bo.readonly
158 - provider =
string.
format(
" %s ", icon.lock),
163 - local file_name_block
= {
164 - init =
function(self)
165 - self.filename
= vim.fs.normalize(vim.api.nvim_buf_get_name(
0))
169 - {
provider =
" " },
172 - {
provider =
"%<" },
175 - local file_type
= {
176 - provider =
function()
177 - return icon.file
.. " " .. string.
upper(vim.bo.filetype)
181 - local file_encoding
= {
182 - provider =
function()
183 - local enc
= (vim.bo.fenc
~= "" and vim.bo.fenc)
or vim.o.enc
184 - return enc
~= "utf-8" and enc:upper()
188 - local file_format
= {
190 - dos = icon.newline
.. icon.carriage_return,
191 - unix = icon.newline,
192 - mac = icon.carriage_return,
194 - provider =
function(self)
195 - local fileformat
= vim.bo.fileformat
196 - return self[fileformat]
200 - local file_size
= {
201 - provider =
function()
204 - local suffix
= {
"b",
"k",
"M",
"G",
"T",
"P",
"E" }
205 - local fsize
= vim.fn.getfsize(vim.api.nvim_buf_get_name(
0))
206 - fsize
= (fsize
< 0 and 0)
or fsize
207 - if fsize
< 1024 then 208 - return fsize
.. suffix[
1]
210 - local i
= math.
floor((
math.
log(fsize)
/ math.
log(
1024)))
211 - return string.
format(
"%.2g%s", fsize
/ math.
pow(
1024, i), suffix[i
+ 1])
215 - local file_last_modified
= {
216 - provider =
function()
217 - local ftime
= vim.fn.getftime(vim.api.nvim_buf_get_name(
0))
219 - local timeago
= require(
"std.timeago")
220 - return timeago.format(ftime)
225 - local lsp_active
= {
227 - condition =
function() vim.lsp.buf_is_attached()
end,
230 - update = {
"LspAttach",
"LspDetach",
"BufEnter",
"BufLeave" },
232 - provider =
function()
234 - for _, client
in pairs(vim.lsp.get_clients({
bufnr =
0 }))
do 235 - table.
insert(names, client.name)
237 - return icon.lsp
.. " " .. table.
concat(names,
" ")
242 - condition =
function()
243 - local ok, navic
= pcall(
require,
"nvim-navic")
244 - return ok
and navic.is_available()
249 - File =
"Directory",
250 - Module =
"@include",
251 - Namespace =
"@namespace",
252 - Package =
"@include",
253 - Class =
"@structure",
254 - Method =
"@method",
255 - Property =
"@property",
257 - Constructor =
"@constructor",
259 - Interface =
"@type",
260 - Function =
"@function",
261 - Variable =
"@variable",
262 - Constant =
"@constant",
263 - String =
"@string",
264 - Number =
"@number",
265 - Boolean =
"@boolean",
270 - EnumMember =
"@field",
271 - Struct =
"@structure",
272 - Event =
"@keyword",
273 - Operator =
"@operator",
274 - TypeParameter =
"@type",
277 - enc =
function(line, col, winnr)
278 - return bit.bor(bit.lshift(line,
16), bit.lshift(col,
6), winnr)
282 - local line
= bit.rshift(c,
16)
283 - local col
= bit.band(bit.rshift(c,
6),
1023)
284 - local winnr
= bit.band(c,
63)
285 - return line, col, winnr
288 - init =
function(self)
289 - local data
= require(
"nvim-navic").get_data()
or {}
290 - local children
= {}
292 - for i, d
in ipairs(data)
do 294 - local pos
= self.enc(d.scope.start.line, d.scope.start.character, self.winnr)
298 - hl = self.type_hl[d.type],
302 - provider = d.name:gsub(
"%%",
"%%%%"):gsub(
"%s*->%s*",
""),
304 - hl = self.type_hl[d.type],
309 - callback =
function(_, minwid)
311 - local line, col, winnr
= self.dec(minwid)
312 - vim.api.nvim_win_set_cursor(vim.fn.win_getid(winnr), { line, col })
314 - name =
"heirline_navic",
319 - if #data
> 1 and i
< #data
then 320 - table.
insert(child, {
325 - table.
insert(children, child)
328 - self.child
= self:new(children,
1)
331 - provider =
function(self)
332 - return self.child:eval()
335 - update =
"CursorMoved",
338 - local diagnostic_enabled
= {
339 - init =
function(self)
340 - self.icon
= (
not vim.diagnostic.is_enabled())
and icon.toggle_off
or icon.toggle_on
342 - provider =
function(self)
343 - return icon.diagnostic
.. " " .. self.icon
347 - local diagnostic
= {
348 - condition = conditions.has_diagnostics,
351 - error_icon = icon.error,
352 - warn_icon = icon.warn,
353 - info_icon = icon.info,
354 - hint_icon = icon.hint,
357 - init =
function(self)
358 - self.errors
= #vim.diagnostic.get(
0, {
severity = vim.diagnostic.severity.ERROR })
359 - self.warnings
= #vim.diagnostic.get(
0, {
severity = vim.diagnostic.severity.WARN })
360 - self.hints
= #vim.diagnostic.get(
0, {
severity = vim.diagnostic.severity.HINT })
361 - self.info
= #vim.diagnostic.get(
0, {
severity = vim.diagnostic.severity.INFO })
364 - update = {
"DiagnosticChanged",
"BufEnter",
"BufLeave" },
367 - provider =
function(self)
369 - return self.errors
> 0 and (self.error_icon
.. " " .. self.errors
.. " ")
371 - hl =
"DiagnosticError",
374 - provider =
function(self)
375 - return self.warnings
> 0 and (self.warn_icon
.. " " .. self.warnings
.. " ")
377 - hl =
"DiagnosticWarn",
380 - provider =
function(self)
381 - return self.info
> 0 and (self.info_icon
.. " " .. self.info
.. " ")
383 - hl =
"DiagnosticInfo",
386 - provider =
function(self)
387 - return self.hints
> 0 and (self.hint_icon
.. " " .. self.hints)
389 - hl =
"DiagnosticHint",
393 - local is_svn_repo = function()
394 - local svn_dir
= vim.fs.find(
".svn", {
396 - stop = vim.uv.os_homedir(),
397 - path = vim.fs.dirname(vim.api.nvim_buf_get_name(
0)),
398 - type =
"directory",
401 - return not vim.tbl_isempty(svn_dir)
404 - local svn_get_relative_url = function()
406 - local job
= require(
"plenary.job")
407 - local relative_url
= {
"[ERR]" }
412 - args = {
"info",
"--show-item",
"relative-url",
"--no-newline" },
413 - on_exit =
function(current_job, exit_code)
414 - if exit_code
== 0 then 415 - relative_url
= current_job:result()
421 - return relative_url[
1]
425 - condition = is_svn_repo,
427 - update =
"BufEnter",
429 - init =
function(self)
430 - self.relative_url
= svn_get_relative_url()
434 - provider =
function(self)
435 - return icon.subversion
.. " " .. icon.branch
.. " " .. self.relative_url
441 - condition = conditions.is_git_repo,
443 - init =
function(self)
444 - self.status_dict
= vim.b.gitsigns_status_dict
448 - provider =
function(self)
449 - return icon.git
.. " " .. icon.branch
.. " " .. self.status_dict.head
.. " " 453 - provider =
function(self)
454 - local count
= self.status_dict.added
or 0 455 - return count
> 0 and (icon.diff_add
.. " " .. count
.. " ")
460 - provider =
function(self)
461 - local count
= self.status_dict.removed
or 0 462 - return count
> 0 and (icon.diff_remove
.. " " .. count
.. " ")
467 - provider =
function(self)
468 - local count
= self.status_dict.changed
or 0 469 - return count
> 0 and (icon.diff_change
.. " " .. count
.. " ")
476 - init =
function(self)
477 - self.icon
= (vim.fn.haslocaldir(
0)
== 1 and icon[
"local"]
or "")
.. " " .. icon.global
.. " " 478 - self.cwd
= vim.fs.normalize(vim.uv.cwd()):gsub(vim.fs.normalize(vim.uv.os_homedir()),
"~")
484 - provider =
function(self)
485 - return self.icon
.. self.cwd
489 - provider =
function(self)
490 - local cwd
= vim.fn.pathshorten(self.cwd)
491 - return self.icon
.. cwd
499 - local help_file_name
= {
500 - condition =
function()
501 - return vim.bo.filetype
== "help" 503 - provider =
function()
504 - local filename
= vim.api.nvim_buf_get_name(
0)
505 - return vim.fn.fnamemodify(filename,
":t")
510 - local terminal_name
= {
511 - provider =
function()
512 - local name, _
= vim.api.nvim_buf_get_name(
0):gsub(
".*:",
"")
513 - local basename
= vim.fs.basename(name)
514 - return icon.terminal
.. " " .. (basename
or "noname")
520 - provider =
function()
521 - local togglers
= require(
"bugabinga.options.togglers")
522 - return tostring(togglers)
526 - local macro_recording
= {
527 - condition =
function()
528 - return vim.fn.reg_recording()
~= "" and vim.o.cmdheight
== 0 530 - provider = icon.macro
.. " ",
532 - utils.surround({
"░▒▓ ",
" ▓▒░" },
nil, {
533 - provider =
function()
534 - return vim.fn.reg_recording()
545 - condition =
function()
546 - local ok, lazy_status
= pcall(
require,
"lazy.status")
547 - return ok
and lazy_status.has_updates()
549 - update = {
"User",
pattern =
"LazyUpdate" },
550 - provider =
function()
551 - return " " .. icon.lazy
.. " " .. require(
"lazy.status").updates()
.. " " 554 - callback =
function()
555 - require(
"lazy").update()
557 - name =
"update_plugins",
561 - local align
= {
provider =
"%=" }
562 - local space
= {
provider =
" " }
564 - local default_statusline
= {
579 - diagnostic_enabled,
591 - file_last_modified,
594 - local special_statusline
= {
595 - condition =
function()
596 - return conditions.buffer_matches({
597 - buftype = ignored.buftypes,
598 - filetype = ignored.filetypes,
608 - local terminal_statusline
= {
610 - condition =
function()
611 - return conditions.buffer_matches({
buftype = {
"terminal" } })
614 - {
condition = conditions.is_active, vi_mode, space },
621 - local inactive_statusline
= {
622 - condition = conditions.is_not_active,
629 - local statuslines
= {
631 - if conditions.is_active()
then 632 - return "StatusLine" 634 - return "StatusLineNC" 638 - fallthrough =
false,
640 - special_statusline,
641 - terminal_statusline,
642 - inactive_statusline,
643 - default_statusline,
648 - if conditions.is_active()
then 655 - fallthrough =
false,
658 - condition =
function()
659 - return conditions.buffer_matches({
buftype = {
"terminal" } })
777 - provider =
function(self)
778 - return "%" .. self.tabnr
.. "T " .. self.tabpage
.. " %T" 780 - hl =
function(self)
781 - if self.is_active
then 782 - return "TabLineSel" 789 - local tab_pages
= {
790 - {
provider =
"%=" },
791 - utils.make_tablist(tabpage),
799 - statusline = statuslines,
801 - tabline = tab_pages,
807 - disable_winbar_cb =
function(args)
808 - return conditions.buffer_matches({
809 - buftype = ignored.buftypes,
810 - filetype = ignored.filetypes,