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',
17 + config =
function ()
18 + local heirline
= require 'heirline' 19 + local conditions
= require 'heirline.conditions' 20 + local utils
= require 'heirline.utils' 22 + local nugu
= require 'bugabinga.nugu.palette' 23 + heirline.load_colors( nugu )
25 + auto
'reload_heirline_colors' {
26 + description =
'Reload dark/light nugu colors for Heirline',
27 + events =
'ColorScheme',
28 + command =
function () utils.on_colorscheme( nugu )
end,
32 + init =
function ( self )
33 + self.mode
= vim.fn.mode(
1 )
39 + no = icon.normal
.. '?',
40 + nov = icon.normal
.. '?',
41 + noV = icon.normal
.. '?',
42 + [
'no\22'] = icon.normal
.. '?',
43 + niI = icon.normal
.. 'i',
44 + niR = icon.normal
.. 'r',
45 + niV = icon.normal
.. 'v',
46 + nt = icon.normal
.. 't',
48 + vs = icon.visual
.. 's',
49 + V = icon.visual
.. '_',
50 + Vs = icon.visual
.. 's',
51 + [
'\22'] =
'^' .. icon.visual,
52 + [
'\22s'] =
'^' .. icon.visual,
54 + S = icon.select
.. '_',
55 + [
'\19'] =
'^' .. icon.select,
57 + ic = icon.insert
.. 'c',
58 + ix = icon.insert
.. 'x',
60 + Rc = icon.replace
.. 'c',
61 + Rx = icon.replace
.. 'x',
62 + Rv = icon.replace
.. 'v',
63 + Rvc = icon.replace
.. 'v',
64 + Rvx = icon.replace
.. 'v',
66 + cv = icon.command
.. 'x',
68 + rm = icon.pending
.. 'm',
69 + [
'r?'] = icon.pending
.. '?',
70 + [
'!'] = icon.exclaim,
76 + v =
'ui_important_global',
77 + V =
'ui_important_global',
78 + [
'\22'] =
'ui_important_global',
79 + c =
'ui_important_global',
80 + s =
'ui_important_global',
81 + S =
'ui_important_global',
82 + [
'\19'] =
'ui_important_global',
83 + R =
'ui_important_global',
84 + r =
'ui_important_global',
85 + [
'!'] =
'ui_important_global',
86 + t =
'ui_important_global',
90 + provider =
function ( self )
91 + local mode_name
= self.mode_names[self.mode]
92 + return ' ' .. icon.vim
.. ' %3(' .. mode_name
.. '%) ' 95 + hl =
function ( self )
96 + local mode
= self.mode:sub(
1,
1 )
97 + return {
fg = self.mode_colors[mode],
bold =
true, }
103 + callback = vim.schedule_wrap(
function () vim.cmd.redrawstatus()
end ),
107 + local file_icon
= {
108 + init =
function ( self )
109 + local filename
= self.filename
110 + local extension
= vim.fn.fnamemodify( filename,
':e' )
111 + self.icon
= require 'nvim-web-devicons'.get_icon_color( filename, extension, {
default =
true, } )
113 + provider =
function ( self )
114 + return self.icon
and (self.icon
.. ' ')
116 + hl =
'DefaultIcon',
119 + local file_name
= {
120 + init =
function ( self )
121 + self.lfilename
= vim.fs.normalize( vim.fn.fnamemodify( self.filename,
':.' ) )
122 + if self.lfilename
== '' then self.lfilename
= NEW_FILE
end 128 + provider =
function ( self )
129 + return self.lfilename
133 + provider =
function ( self )
134 + return vim.fs.normalize( vim.fn.pathshorten( self.lfilename ) )
139 + local file_flags
= {
141 + condition =
function ()
142 + return vim.bo.modified
144 + provider =
string.
format(
' %s ', icon.modified ),
148 + condition =
function ()
149 + return not vim.bo.modifiable
or vim.bo.readonly
151 + provider =
string.
format(
' %s ', icon.lock ),
156 + local file_name_block
= {
157 + init =
function ( self )
158 + self.filename
= vim.fs.normalize( vim.api.nvim_buf_get_name(
0 ) )
162 + {
provider =
' ', },
165 + {
provider =
'%<', },
168 + local file_type
= {
169 + provider =
function ()
170 + return icon.file
.. ' ' .. string.
upper( vim.bo.filetype )
174 + local file_encoding
= {
175 + provider =
function ()
176 + local enc
= (vim.bo.fenc
~= '' and vim.bo.fenc)
or vim.o.enc
177 + return enc
~= 'utf-8' and enc:upper()
181 + local file_format
= {
183 + dos = icon.newline
.. icon.carriage_return,
184 + unix = icon.newline,
185 + mac = icon.carriage_return,
187 + provider =
function ( self )
188 + local fileformat
= vim.bo.fileformat
189 + return self[fileformat]
193 + local file_size
= {
194 + provider =
function ()
197 + local suffix
= {
'b',
'k',
'M',
'G',
'T',
'P',
'E', }
198 + local fsize
= vim.fn.getfsize( vim.api.nvim_buf_get_name(
0 ) )
199 + fsize
= (fsize
< 0 and 0)
or fsize
200 + if fsize
< 1024 then 201 + return fsize
.. suffix[
1]
203 + local i
= math.
floor( (
math.
log( fsize )
/ math.
log(
1024 )) )
204 + return string.
format(
'%.2g%s', fsize
/ math.
pow(
1024, i ), suffix[i
+ 1] )
208 + local file_last_modified
= {
209 + provider =
function ()
210 + local ftime
= vim.fn.getftime( vim.api.nvim_buf_get_name(
0 ) )
212 + local timeago
= require 'std.timeago' 213 + return timeago.format( ftime )
218 + local lsp_active
= {
219 + condition = conditions.lsp_attached,
222 + update = {
'LspAttach',
'LspDetach',
'BufEnter',
'BufLeave', },
224 + provider =
function ()
226 + for _, client
in pairs( vim.lsp.get_clients {
bufnr =
0, } )
do 227 + table.
insert( names, client.name )
229 + return icon.lsp
.. ' ' .. table.
concat( names,
' ' )
233 + local diagnostic_enabled
= {
234 + init =
function ( self )
235 + self.icon
= vim.diagnostic.is_disabled()
and icon.toggle_off
or icon.toggle_on
237 + provider =
function ( self )
238 + return icon.diagnostic
.. ' ' .. self.icon
242 + local diagnostic
= {
243 + condition = conditions.has_diagnostics,
246 + error_icon = icon.error,
247 + warn_icon = icon.warn,
248 + info_icon = icon.info,
249 + hint_icon = icon.hint,
252 + init =
function ( self )
253 + self.errors
= #vim.diagnostic.get(
0, {
severity = vim.diagnostic.severity.ERROR, } )
254 + self.warnings
= #vim.diagnostic.get(
0, {
severity = vim.diagnostic.severity.WARN, } )
255 + self.hints
= #vim.diagnostic.get(
0, {
severity = vim.diagnostic.severity.HINT, } )
256 + self.info
= #vim.diagnostic.get(
0, {
severity = vim.diagnostic.severity.INFO, } )
259 + update = {
'DiagnosticChanged',
'BufEnter', },
262 + provider =
function ( self )
264 + return self.errors
> 0 and (self.error_icon
.. ' ' .. self.errors
.. ' ')
266 + hl =
'DiagnosticError',
269 + provider =
function ( self )
270 + return self.warnings
> 0 and (self.warn_icon
.. ' ' .. self.warnings
.. ' ')
272 + hl =
'DiagnosticWarn',
275 + provider =
function ( self )
276 + return self.info
> 0 and (self.info_icon
.. ' ' .. self.info
.. ' ')
278 + hl =
'DiagnosticInfo',
281 + provider =
function ( self )
282 + return self.hints
> 0 and (self.hint_icon
.. ' ' .. self.hints)
284 + hl =
'DiagnosticHint',
288 + local is_svn_repo = function ()
289 + local svn_dir
= vim.fs.find(
'.svn', {
291 + stop = vim.uv.os_homedir(),
292 + path = vim.fs.dirname( vim.api.nvim_buf_get_name(
0 ) ),
293 + type =
'directory',
296 + return not vim.tbl_isempty( svn_dir )
299 + local svn_get_relative_url = function ()
301 + local job
= require 'plenary.job' 302 + local relative_url
= {
'[ERR]', }
306 + args = {
'info',
'--show-item',
'relative-url',
'--no-newline', },
307 + on_exit =
function ( current_job, exit_code )
308 + if exit_code
== 0 then relative_url
= current_job:result()
end 312 + return relative_url[
1]
316 + condition = is_svn_repo,
318 + update =
'BufEnter',
320 + init =
function ( self )
321 + self.relative_url
= svn_get_relative_url()
325 + provider =
function ( self )
326 + return icon.subversion
.. ' ' .. icon.branch
.. ' ' .. self.relative_url
333 + condition = conditions.is_git_repo,
335 + init =
function ( self )
336 + self.status_dict
= vim.b.gitsigns_status_dict
340 + provider =
function ( self )
341 + return icon.git
.. ' ' .. icon.branch
.. ' ' .. self.status_dict.head
.. ' ' 345 + provider =
function ( self )
346 + local count
= self.status_dict.added
or 0 347 + return count
> 0 and (icon.diff_add
.. ' ' .. count
.. ' ')
352 + provider =
function ( self )
353 + local count
= self.status_dict.removed
or 0 354 + return count
> 0 and (icon.diff_remove
.. ' ' .. count
.. ' ')
359 + provider =
function ( self )
360 + local count
= self.status_dict.changed
or 0 361 + return count
> 0 and (icon.diff_change
.. ' ' .. count
.. ' ')
368 + init =
function ( self )
369 + self.icon
= (vim.fn.haslocaldir(
0 )
== 1 and icon[
'local']
or '')
.. ' ' .. icon.global
.. ' ' 370 + self.cwd
= vim.fs.normalize( vim.uv.cwd() ):gsub( vim.fs.normalize( vim.uv.os_homedir() ),
'~' )
376 + provider =
function ( self )
377 + return self.icon
.. self.cwd
381 + provider =
function ( self )
382 + local cwd
= vim.fn.pathshorten( self.cwd )
383 + return self.icon
.. cwd
391 + local help_file_name
= {
392 + condition =
function ()
393 + return vim.bo.filetype
== 'help' 395 + provider =
function ()
396 + local filename
= vim.api.nvim_buf_get_name(
0 )
397 + return vim.fn.fnamemodify( filename,
':t' )
402 + local terminal_name
= {
403 + provider =
function ()
404 + local name, _
= vim.api.nvim_buf_get_name(
0 ):gsub(
'.*:',
'' )
405 + local basename
= vim.fs.basename( name )
406 + return icon.terminal
.. ' ' .. (basename
or 'noname')
412 + provider =
function ()
413 + local togglers
= require 'bugabinga.options.togglers' 414 + return tostring( togglers )
418 + local macro_recording
= {
419 + condition =
function ()
420 + return vim.fn.reg_recording()
~= '' and vim.o.cmdheight
== 0 422 + provider = icon.macro
.. ' ',
424 + utils.surround( {
'░▒▓ ',
' ▓▒░', },
nil, {
425 + provider =
function ()
426 + return vim.fn.reg_recording()
437 + condition =
function ()
438 + local ok, lazy_status
= pcall(
require,
'lazy.status' )
439 + return ok
and lazy_status.has_updates()
441 + update = {
'User',
pattern =
'LazyUpdate', },
442 + provider =
function ()
return ' ' .. icon.lazy
.. ' ' .. require 'lazy.status'.updates()
.. ' ' end,
444 + callback =
function ()
require 'lazy'.update()
end,
445 + name =
'update_plugins',
449 + local align
= {
provider =
'%=', }
450 + local space
= {
provider =
' ', }
452 + local default_statusline
= {
453 + vi_mode, macro_recording, align,
454 + work_dir, space, git, svn, align,
455 + diagnostic_enabled, space, diagnostic, space, lsp_active, align,
457 + lazy, space, file_encoding, space, file_format, space, file_type, space, file_size, space, file_last_modified,
460 + local special_statusline
= {
461 + condition =
function ()
462 + return conditions.buffer_matches {
463 + buftype = ignored.buftypes,
464 + filetype = ignored.filetypes,
474 + local terminal_statusline
= {
476 + condition =
function ()
477 + return conditions.buffer_matches {
buftype = {
'terminal', }, }
480 + {
condition = conditions.is_active, vi_mode, space, },
487 + local inactive_statusline
= {
488 + condition = conditions.is_not_active,
495 + local statuslines
= {
497 + if conditions.is_active()
then 498 + return 'StatusLine' 500 + return 'StatusLineNC' 504 + fallthrough =
false,
506 + special_statusline,
507 + terminal_statusline,
508 + inactive_statusline,
509 + default_statusline,
514 + if conditions.is_active()
then 521 + fallthrough =
false,
524 + condition =
function ()
525 + return conditions.buffer_matches {
buftype = {
'terminal', }, }
536 + local tabline_buffer_number
= {
537 + provider =
function ( self )
538 + return '(' .. tostring( self.bufnr )
.. ')' 540 + hl =
function ( self )
541 + if self.is_active
then 542 + return {
fg = utils.get_highlight
'TabLineSel'.fg, }
543 + elseif not vim.api.nvim_buf_is_loaded( self.bufnr )
then 544 + return {
fg = utils.get_highlight
'StatusLineNc'.fg, }
546 + return {
fg = utils.get_highlight
'TabLine'.fg, }
551 + local tabline_file_name
= {
552 + provider =
function ( self )
553 + local name
= self.file_name
554 + return name
== '' and NEW_FILE
or vim.fs.normalize( vim.fn.fnamemodify( name,
':t' ) )
556 + hl =
function ( self )
return {
bold = self.is_active
or self.is_visible,
italic =
true, }
end,
559 + local tabline_file_flags
= {
561 + condition =
function ( self )
return vim.api.nvim_get_option_value(
'modified', {
buf = self.bufnr, } )
end,
562 + provider = icon.modified
.. ' ',
565 + condition =
function ( self )
566 + return not vim.api.nvim_get_option_value(
'modifiable', {
buf = self.bufnr, } )
or 567 + vim.api.nvim_get_option_value(
'readonly', {
buf = self.bufnr, } )
569 + provider =
function ( self )
570 + if vim.api.nvim_get_option_value(
'buftype', {
buf = self.bufnr, } )
== 'terminal' then 571 + return icon.terminal
580 + local tabline_file_name_block
= {
581 + init =
function ( self )
582 + self.file_name
= vim.api.nvim_buf_get_name( self.bufnr )
585 + hl =
function ( self )
586 + if self.is_active
then 587 + return 'TabLineSel' 588 + elseif not vim.api.nvim_buf_is_loaded( self.bufnr )
then 589 + return {
fg = utils.get_highlight
'StatusLineNc'.fg, }
596 + callback =
function ( _, minwid, _, button )
597 + if button
== 'm' then 598 + vim.schedule(
function ()
599 + vim.api.nvim_buf_delete( minwid, {
force =
false, } )
600 + vim.cmd.redrawtabline()
603 + vim.api.nvim_win_set_buf(
0, minwid )
606 + minwid =
function ( self )
return self.bufnr
end,
607 + name =
'heirline_tabline_buffer_callback',
611 + {
provider =
' ', },
613 + tabline_buffer_number,
614 + tabline_file_flags,
617 + local tabline_buffer_block
= utils.surround(
619 + ' ' .. icon.slant_left,
620 + icon.slant_right
.. ' ',
623 + if self.is_active
then 624 + return utils.get_highlight
'TabLine'.bg
626 + return utils.get_highlight
'TabLineFill'.bg
629 + { tabline_file_name_block, }
632 + local buffer_line
= utils.make_buflist(
633 + tabline_buffer_block,
634 + {
provider = icon.arrow_left
.. ' ',
hl =
'TabLine', },
635 + {
provider =
' ' .. icon.arrow_right,
hl =
'TabLine', }
639 + provider =
function ( self )
640 + return '%' .. self.tabnr
.. 'T ' .. self.tabpage
.. ' %T' 642 + hl =
function ( self )
643 + if self.is_active
then 644 + return 'TabLineSel' 651 + local tab_pages
= {
652 + {
provider =
'%=', },
653 + utils.make_tablist( tabpage ),
656 + local tabline
= { buffer_line, tab_pages, }
661 + statusline = statuslines,
668 + disable_winbar_cb =
function ( args )
669 + return conditions.buffer_matches(
671 + buftype = ignored.buftypes,
672 + filetype = ignored.filetypes,