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 + {
'echasnovski/mini.diff',
lazy =
true, },
16 + {
'SmiteshP/nvim-navic',
lazy =
true, },
18 + config =
function ()
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
.. '%) ' 98 + hl =
function ( self )
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
= {
226 + condition = conditions.lsp_attached,
229 + update = {
'LspAttach',
'LspDetach',
'BufEnter',
'BufLeave', },
231 + provider =
function ()
233 + for _, client
in pairs( vim.lsp.get_clients {
bufnr =
0, } )
do 234 + table.
insert( names, client.name )
236 + return icon.lsp
.. ' ' .. table.
concat( names,
' ' )
241 + condition =
function ()
242 + local ok, navic
= pcall(
require,
'nvim-navic' )
243 + return ok
and navic.is_available()
248 + File =
'Directory',
249 + Module =
'@include',
250 + Namespace =
'@namespace',
251 + Package =
'@include',
252 + Class =
'@structure',
253 + Method =
'@method',
254 + Property =
'@property',
256 + Constructor =
'@constructor',
258 + Interface =
'@type',
259 + Function =
'@function',
260 + Variable =
'@variable',
261 + Constant =
'@constant',
262 + String =
'@string',
263 + Number =
'@number',
264 + Boolean =
'@boolean',
269 + EnumMember =
'@field',
270 + Struct =
'@structure',
271 + Event =
'@keyword',
272 + Operator =
'@operator',
273 + TypeParameter =
'@type',
276 + enc =
function ( line, col, winnr )
277 + return bit.bor( bit.lshift( line,
16 ), bit.lshift( col,
6 ), winnr )
280 + dec =
function ( c )
281 + local line
= bit.rshift( c,
16 )
282 + local col
= bit.band( bit.rshift( c,
6 ),
1023 )
283 + local winnr
= bit.band( c,
63 )
284 + return line, col, winnr
287 + init =
function ( self )
288 + local data
= require 'nvim-navic'.get_data()
or {}
289 + local children
= {}
291 + for i, d
in ipairs( data )
do 293 + local pos
= self.enc( d.scope.start.line, d.scope.start.character, self.winnr )
297 + hl = self.type_hl[d.type],
301 + provider = d.name:gsub(
'%%',
'%%%%' ):gsub(
'%s*->%s*',
'' ),
303 + hl = self.type_hl[d.type],
308 + callback =
function ( _, minwid )
310 + local line, col, winnr
= self.dec( minwid )
311 + vim.api.nvim_win_set_cursor( vim.fn.win_getid( winnr ), { line, col, } )
313 + name =
'heirline_navic',
318 + if #data
> 1 and i
< #data
then 319 + table.
insert( child, {
324 + table.
insert( children, child )
327 + self.child
= self:new( children,
1 )
330 + provider =
function ( self )
331 + return self.child:eval()
334 + update =
'CursorMoved',
337 + local diagnostic_enabled
= {
338 + init =
function ( self )
339 + self.icon
= (
not vim.diagnostic.is_enabled())
and icon.toggle_off
or icon.toggle_on
341 + provider =
function ( self )
342 + return icon.diagnostic
.. ' ' .. self.icon
346 + local diagnostic
= {
347 + condition = conditions.has_diagnostics,
350 + error_icon = icon.error,
351 + warn_icon = icon.warn,
352 + info_icon = icon.info,
353 + hint_icon = icon.hint,
356 + init =
function ( self )
357 + self.errors
= #vim.diagnostic.get(
0, {
severity = vim.diagnostic.severity.ERROR, } )
358 + self.warnings
= #vim.diagnostic.get(
0, {
severity = vim.diagnostic.severity.WARN, } )
359 + self.hints
= #vim.diagnostic.get(
0, {
severity = vim.diagnostic.severity.HINT, } )
360 + self.info
= #vim.diagnostic.get(
0, {
severity = vim.diagnostic.severity.INFO, } )
363 + update = {
'DiagnosticChanged',
'BufEnter',
'BufLeave', },
366 + provider =
function ( self )
368 + return self.errors
> 0 and (self.error_icon
.. ' ' .. self.errors
.. ' ')
370 + hl =
'DiagnosticError',
373 + provider =
function ( self )
374 + return self.warnings
> 0 and (self.warn_icon
.. ' ' .. self.warnings
.. ' ')
376 + hl =
'DiagnosticWarn',
379 + provider =
function ( self )
380 + return self.info
> 0 and (self.info_icon
.. ' ' .. self.info
.. ' ')
382 + hl =
'DiagnosticInfo',
385 + provider =
function ( self )
386 + return self.hints
> 0 and (self.hint_icon
.. ' ' .. self.hints)
388 + hl =
'DiagnosticHint',
392 + local is_svn_repo = function ()
393 + local svn_dir
= vim.fs.find(
'.svn', {
395 + stop = vim.uv.os_homedir(),
396 + path = vim.fs.dirname( vim.api.nvim_buf_get_name(
0 ) ),
397 + type =
'directory',
400 + return not vim.tbl_isempty( svn_dir )
403 + local svn_get_relative_url = function ()
405 + local job
= require 'plenary.job' 406 + local relative_url
= {
'[ERR]', }
411 + args = {
'info',
'--show-item',
'relative-url',
'--no-newline', },
412 + on_exit =
function ( current_job, exit_code )
413 + if exit_code
== 0 then 414 + relative_url
= current_job:result()
420 + return relative_url[
1]
424 + condition = is_svn_repo,
426 + update =
'BufEnter',
428 + init =
function ( self )
429 + self.relative_url
= svn_get_relative_url()
433 + provider =
function ( self )
434 + return icon.subversion
.. ' ' .. icon.branch
.. ' ' .. self.relative_url
440 + condition = conditions.is_git_repo,
442 + init =
function ( self )
443 + self.status_dict
= vim.b.minidiff_summary
447 + provider =
function ( self )
448 + return icon.git
.. ' ' .. icon.branch
.. ' ' .. self.status_dict.source_name
.. ' ' 452 + provider =
function ( self )
453 + local count
= self.status_dict.add
or 0 454 + return count
> 0 and (icon.diff_add
.. ' ' .. count
.. ' ')
459 + provider =
function ( self )
460 + local count
= self.status_dict.delete
or 0 461 + return count
> 0 and (icon.diff_remove
.. ' ' .. count
.. ' ')
466 + provider =
function ( self )
467 + local count
= self.status_dict.change
or 0 468 + return count
> 0 and (icon.diff_change
.. ' ' .. count
.. ' ')
475 + init =
function ( self )
476 + self.icon
= (vim.fn.haslocaldir(
0 )
== 1 and icon[
'local']
or '')
.. ' ' .. icon.global
.. ' ' 477 + self.cwd
= vim.fs.normalize( vim.uv.cwd() ):gsub( vim.fs.normalize( vim.uv.os_homedir() ),
'~' )
483 + provider =
function ( self )
484 + return self.icon
.. self.cwd
488 + provider =
function ( self )
489 + local cwd
= vim.fn.pathshorten( self.cwd )
490 + return self.icon
.. cwd
498 + local help_file_name
= {
499 + condition =
function ()
500 + return vim.bo.filetype
== 'help' 502 + provider =
function ()
503 + local filename
= vim.api.nvim_buf_get_name(
0 )
504 + return vim.fn.fnamemodify( filename,
':t' )
509 + local terminal_name
= {
510 + provider =
function ()
511 + local name, _
= vim.api.nvim_buf_get_name(
0 ):gsub(
'.*:',
'' )
512 + local basename
= vim.fs.basename( name )
513 + return icon.terminal
.. ' ' .. (basename
or 'noname')
519 + provider =
function ()
520 + local togglers
= require 'bugabinga.options.togglers' 521 + return tostring( togglers )
525 + local macro_recording
= {
526 + condition =
function ()
527 + return vim.fn.reg_recording()
~= '' and vim.o.cmdheight
== 0 529 + provider = icon.macro
.. ' ',
531 + utils.surround( {
'░▒▓ ',
' ▓▒░', },
nil, {
532 + provider =
function ()
533 + return vim.fn.reg_recording()
544 + condition =
function ()
545 + local ok, lazy_status
= pcall(
require,
'lazy.status' )
546 + return ok
and lazy_status.has_updates()
548 + update = {
'User',
pattern =
'LazyUpdate', },
549 + provider =
function ()
550 + return ' ' .. icon.lazy
.. ' ' .. require 'lazy.status'.updates()
.. ' ' 553 + callback =
function ()
554 + require 'lazy'.update()
556 + name =
'update_plugins',
560 + local align
= {
provider =
'%=', }
561 + local space
= {
provider =
' ', }
563 + local default_statusline
= {
578 + diagnostic_enabled,
590 + file_last_modified,
593 + local special_statusline
= {
594 + condition =
function ()
595 + return conditions.buffer_matches {
596 + buftype = ignored.buftypes,
597 + filetype = ignored.filetypes,
607 + local terminal_statusline
= {
609 + condition =
function ()
610 + return conditions.buffer_matches {
buftype = {
'terminal', }, }
613 + {
condition = conditions.is_active, vi_mode, space, },
620 + local inactive_statusline
= {
621 + condition = conditions.is_not_active,
628 + local statuslines
= {
630 + if conditions.is_active()
then 631 + return 'StatusLine' 633 + return 'StatusLineNC' 637 + fallthrough =
false,
639 + special_statusline,
640 + terminal_statusline,
641 + inactive_statusline,
642 + default_statusline,
647 + if conditions.is_active()
then 654 + fallthrough =
false,
657 + condition =
function ()
658 + return conditions.buffer_matches {
buftype = {
'terminal', }, }
776 + provider =
function ( self )
777 + return '%' .. self.tabnr
.. 'T ' .. self.tabpage
.. ' %T' 779 + hl =
function ( self )
780 + if self.is_active
then 781 + return 'TabLineSel' 788 + local tab_pages
= {
789 + {
provider =
'%=', },
790 + utils.make_tablist( tabpage ),
798 + statusline = statuslines,
800 + tabline = tab_pages,
806 + disable_winbar_cb =
function ( args )
807 + return conditions.buffer_matches( {
808 + buftype = ignored.buftypes,
809 + filetype = ignored.filetypes,