1 1 local wez
= require 'wezterm' 2 2 local bat
= require 'bugabinga.battery' 4 -local DELIMITER
= ' · ' 5 4 local nugu_dark
= require 'bugabinga.nugu.palette_dark'.palette
6 5 local nugu_light
= require 'bugabinga.nugu.palette_light'.palette
7 6 local palette
= nugu_dark
8 -package.
loaded[
'bugabinga.apps']
= nil 9 -local apps
= require 'bugabinga.apps' 11 -local FALLBACK_TAB_PROGRAM
= 'nu' 8 +local clean = function ( value )
9 + if not value
or value
== '' then return nil end 10 + value
= value:gsub(
'^%s+',
'' ):gsub(
'%s+$',
'' )
11 + if value
== '' then return nil end 13 -local tab_activity_until
= {}
15 -local wall_seconds = function ()
15 +local basename = function ( value )
16 + if not value
or value
== '' then return nil end 17 + value
= value:gsub(
'\\',
'/' )
18 + return value:match(
'([^/]+)$' )
or value
19 21 local use_palette_for_scheme = function ( scheme )
25 27 if ok
and config
then use_palette_for_scheme( config.color_scheme )
end 30 +local short_workspace = function ( name )
31 + name
= clean( name )
or 'default' 32 + local home
= wez.home_dir
33 + if home
and name:sub(
1,
#home )
== home
then 34 + name
= '~' .. name:sub(
#home
+ 1 )
36 + if name:find(
'/',
1,
true )
or name:find(
'\\',
1,
true )
then 37 + name
= basename( name )
or name
39 + return wez.truncate_right( name,
18 )
42 +local primary_pane = function ( tab )
44 + for _, pane
in ipairs( tab.panes
or {} )
do 45 + if not primary
or (pane.pane_index
or 0)
< (primary.pane_index
or 0)
then 49 + return primary
or tab.active_pane
52 +local tab_text = function ( tab )
53 + local pane
= primary_pane( tab )
54 + return clean( tab.tab_title )
55 + or clean( pane
and pane.title )
56 + or clean( tab.active_pane
and tab.active_pane.title )
28 60 local zoomed = function ( pane )
29 61 local tab
= pane:tab()
30 62 if not tab
then return nil end 32 64 for _, info
in ipairs( tab:panes_with_info() )
do 33 - if info.is_zoomed
then return '🔎 Zoomed Pane' end 65 + if info.is_zoomed
then return 'zoom' end 39 -local safe_user_vars = function ( pane )
40 - local ok, vars
= pcall( pane.get_user_vars, pane )
41 - if ok
and vars
then return vars
end 45 -local basename = function ( value )
46 - if not value
or value
== '' then return nil end 47 - value
= value:gsub(
'\\',
'/' )
48 - return value:match(
'([^/]+)$' )
or value
51 -local program_icon = function ( program )
52 - return apps.icon( program, wez.nerdfonts )
55 -local pulse_color = function ()
56 - return palette.ui.important_local
59 -local busy_badge = function ()
60 - return '●', pulse_color()
63 -local progress_badge = function ( progress )
64 - if not progress
or progress
== 'None' then return nil end 65 - if progress
== 'Indeterminate' then return busy_badge()
end 66 - if type( progress )
== 'table' and progress.Error
~= nil then return '✗', palette.error
end 67 - if type( progress )
== 'table' and progress.Percentage
~= nil then return busy_badge()
end 71 -local colored_badge = function ( elements, badge, color, fallback )
72 - if not badge
then return end 73 - table.
insert( elements, {
Text =
' ' } )
74 - table.
insert( elements, {
Foreground = {
Color = color
or fallback } } )
75 - table.
insert( elements, {
Text = badge } )
76 - table.
insert( elements, {
Foreground = {
Color = fallback } } )
79 -local fixed_badge = function ( elements, badge, color, fallback )
80 - table.
insert( elements, {
Text =
' ' } )
81 - table.
insert( elements, {
Foreground = {
Color = color
or fallback } } )
82 - table.
insert( elements, {
Text = badge
or ' ' } )
83 - table.
insert( elements, {
Foreground = {
Color = fallback } } )
86 -local state_badge = function ( state )
87 - if state
== 'busy' or state
== 'running' or state
== 'thinking' or state
== 'loading' then return busy_badge()
end 88 - if state
== 'done' or state
== 'success' then return '✓', palette.ui.important_local
end 89 - if state
== 'error' or state
== 'failed' then return '✗', palette.error
end 90 - if state
== 'aborted' then return '×', palette.warning
end 91 - if state
== 'waiting' or state
== 'input' or state
== 'needs_input' then return '?', palette.warning
end 95 -local user_state_badge = function ( vars )
97 - local badge, color
= state_badge( vars.WEZTERM_STATE )
98 - if badge
then return badge, color
end 99 - return state_badge( vars.PI_STATE )
102 -local ACTIVITY_MARKERS
= {
104 - '◌',
'○',
'◐',
'◓',
'◑',
'◒',
'◎',
'◉',
'●',
105 - '◜',
'◠',
'◝',
'◞',
'◡',
'◟',
106 - '⠁',
'⠂',
'⠄',
'⠆',
'⠇',
'⠋',
'⠙',
'⠹',
'⠸',
'⠼',
'⠴',
'⠦',
'⠧',
'⠏',
'⠐',
107 - '⣾',
'⣽',
'⣻',
'⢿',
'⡿',
'⣟',
'⣯',
'⣷',
108 - '✳',
'✢',
'✣',
'✤',
'✥',
'✦',
'✧',
'✶',
'✷',
'✸',
'✹',
'✺',
'✻',
'✼',
'✽',
'✾',
'✿',
111 -local strip_activity_marker = function ( title )
112 - title
= apps.clean_title( title )
113 - if not title
then return nil,
false end 115 - local had_marker
= false 116 - local changed
= true 119 - title
= apps.clean_title( title )
or title
120 - for _, marker
in ipairs( ACTIVITY_MARKERS )
do 121 - if title:sub(
1,
#marker )
== marker
then 122 - title
= title:sub(
#marker
+ 1 )
126 - if title:sub(
-#marker )
== marker
then 127 - title
= title:sub(
1,
#title
- #marker )
134 - return apps.clean_title( title ), had_marker
137 -local activity_badge = function ( title )
138 - local _, had_marker
= strip_activity_marker( title )
139 - if had_marker
then return busy_badge()
end 143 -local short_workspace = function ( name )
144 - local home
= wez.home_dir
145 - if home
and name:sub(
1,
#home )
== home
then 146 - name
= '~' .. name:sub(
#home
+ 1 )
151 - if name:find(
'/',
1,
true )
or name:find(
'\\',
1,
true )
then 152 - return basename( name )
or name
156 - return wez.truncate_right( name,
16 )
161 -local workspace_summaries = function ()
162 - local ok, mux_windows
= pcall( wez.mux.all_windows )
163 - if not ok
then return {}
end 165 - local summaries
= {}
166 - for _, mux_window
in ipairs( mux_windows )
do 167 - local ok_workspace, workspace
= pcall(
function ()
return mux_window:get_workspace()
end )
168 - if ok_workspace
and workspace
then 169 - local summary
= summaries[workspace]
170 - if not summary
then 171 - summary
= {
name = workspace,
windows =
0,
tabs =
0,
panes =
0,
badge =
nil,
badge_color =
nil }
172 - summaries[workspace]
= summary
174 - summary.windows
= summary.windows
+ 1 176 - local ok_tabs, tabs
= pcall(
function ()
return mux_window:tabs()
end )
178 - for _, tab
in ipairs( tabs )
do 179 - summary.tabs
= summary.tabs
+ 1 180 - local ok_panes, panes
= pcall(
function ()
return tab:panes_with_info()
end )
182 - for _, info
in ipairs( panes )
do 183 - summary.panes
= summary.panes
+ 1 184 - local vars
= safe_user_vars( info.pane )
185 - local badge, color
= user_state_badge( vars )
186 - if badge
and (
not summary.badge
or badge
== '✗' or badge
== '?')
then 187 - summary.badge
= badge
188 - summary.badge_color
= color
200 -local workspace_hud = function ( active_workspace )
201 - local summaries
= workspace_summaries()
203 - for name
in pairs( summaries )
do table.
insert( names, name )
end 204 - table.
sort( names )
207 - if summaries[active_workspace]
then table.
insert( ordered, active_workspace )
end 208 - for _, name
in ipairs( names )
do 209 - if name
~= active_workspace
then table.
insert( ordered, name )
end 212 - local elements
= {}
214 - for _, name
in ipairs( ordered )
do 216 - if shown
> 5 then break end 218 - local active
= name
== active_workspace
219 - local fg
= active
and palette.ui.important_local
or palette.ui.minor
220 - local summary
= summaries[name]
221 - table.
insert( elements, {
Foreground = {
Color = fg } } )
222 - if active
then table.
insert( elements, {
Attribute = {
Intensity =
'Bold' } } )
end 223 - table.
insert( elements, {
Text = (active
and ' ● ' or ' ○ ')
.. short_workspace( summary.name ) } )
225 - colored_badge( elements, summary.badge, summary.badge_color, fg )
227 - if active
and summary.tabs
> 1 then 228 - table.
insert( elements, {
Text =
' ' .. tostring( summary.tabs )
.. 't' } )
230 - table.
insert( elements, {
Text =
' ' } )
231 - table.
insert( elements, {
Attribute = {
Intensity =
'Normal' } } )
234 - if #ordered
> 5 then 235 - table.
insert( elements, {
Foreground = {
Color = palette.ui.minor } } )
236 - table.
insert( elements, {
Text =
' +' .. tostring(
#ordered
- 5 )
.. ' ' } )
239 - table.
insert( elements, {
Text =
' ' } )
244 -local nerd_icon = function ( fallback,
... )
245 - for _, name
in ipairs {
... }
do 246 - if wez.nerdfonts[name]
then return wez.nerdfonts[name]
end 251 71 local host_domain = function ()
252 72 local triple
= wez.target_triple
or '' 253 - if triple:find(
'windows',
1,
true )
then 254 - return 'WIN', nerd_icon(
'□',
'dev_windows',
'md_microsoft_windows',
'cod_terminal_powershell' ), palette.warning
255 - elseif triple:find(
'darwin',
1,
true )
then 256 - return 'MAC', nerd_icon(
'□',
'dev_apple',
'fa_apple' ), palette.ui.important_local
257 - elseif triple:find(
'linux',
1,
true )
then 258 - return 'LIN', nerd_icon(
'□',
'dev_linux',
'cod_terminal_linux' ), palette.ui.important_local
259 - elseif triple:find(
'bsd',
1,
true )
then 260 - return 'BSD', nerd_icon(
'□',
'dev_freebsd' ), palette.ui.important_local
262 - return 'LOC', nerd_icon(
'□',
'cod_terminal' ), palette.ui.important_local
73 + if triple:find(
'windows',
1,
true )
then return 'WIN', wez.nerdfonts.dev_windows
or '□', palette.warning
end 74 + if triple:find(
'darwin',
1,
true )
then return 'MAC', wez.nerdfonts.dev_apple
or '□', palette.ui.important_local
end 75 + if triple:find(
'linux',
1,
true )
then return 'LIN', wez.nerdfonts.dev_linux
or '□', palette.ui.important_local
end 76 + if triple:find(
'bsd',
1,
true )
then return 'BSD', wez.nerdfonts.dev_freebsd
or '□', palette.ui.important_local
end 77 + return 'LOC', wez.nerdfonts.cod_terminal
or '□', palette.ui.important_local
265 -local domain_hud = function ( domain )
266 - local label, icon, color
268 - if not domain
or domain
== 'local' or domain
== 'Local' then 269 - label, icon, color
= host_domain()
270 - elseif domain:find(
'^WSL:',
1,
false )
then 272 - icon
= nerd_icon(
'□',
'dev_linux',
'cod_terminal_linux' )
273 - color
= palette.ui.important_local
274 - elseif domain:find(
'^scope:',
1,
false )
then 276 - icon
= nerd_icon(
'□',
'cod_gear',
'md_cog' )
277 - color
= palette.warning
279 - label
= ( domain:upper():gsub(
'[^%w]',
'' ):sub(
1,
3 )
.. 'LOC' ):sub(
1,
3 )
280 - icon
= nerd_icon(
'□',
'cod_terminal' )
281 - color
= palette.ui.important_local
285 - {
Foreground = {
Color = color } },
286 - {
Attribute = {
Intensity =
'Bold' } },
287 - {
Text = icon
.. ' ' .. label
.. ' ' },
288 - {
Attribute = {
Intensity =
'Normal' } },
292 -local root_or_nil = function ( program )
293 - program
= apps.normalize( program )
294 - if apps.is_root( program )
then return program
end 298 -local tab_label = function ( program, detail )
299 - program
= root_or_nil( program )
or FALLBACK_TAB_PROGRAM
300 - local base
= apps.label( program )
or apps.label( FALLBACK_TAB_PROGRAM )
301 - return detail
and (base
.. ' · ' .. detail)
or base
304 -local title_program = function ( title )
305 - title
= strip_activity_marker( title )
306 - if not title
then return nil end 307 - if title:sub(
1,
#'π' )
== 'π' then return 'pi' end 311 - return root_or_nil( title:match(
'^([%w%._%-]+)' ) )
314 -local title_detail = function ( title, program, include_shell_titles )
315 - title
= strip_activity_marker( title )
316 - if not title
then return nil end 318 - local detail
= apps.title_detail( title, program, include_shell_titles )
or title
319 - detail
= strip_activity_marker( detail )
320 - detail
= apps.clean_title( detail )
321 - if not detail
or apps.normalize( detail )
== apps.normalize( program )
then return nil end 325 -local detect_from_process_info = function ( info )
326 - local detected
= nil 328 - visit = function ( node )
329 - if detected
or type( node )
~= 'table' then return end 331 - for _, key
in ipairs {
'name',
'executable' }
do 332 - detected
= detected
or root_or_nil( node[key] )
334 - if type( node.argv )
== 'table' then 335 - for _, arg
in ipairs( node.argv )
do 336 - detected
= detected
or root_or_nil( arg )
339 - if detected
then return end 341 - if type( node.children )
== 'table' then 342 - for _, child
in pairs( node.children )
do visit( child )
end 349 -local process_info_program = function ( tab )
350 - local pane_id
= tab.active_pane
and tab.active_pane.pane_id
351 - if not pane_id
then return nil end 353 - local ok_pane, mux_pane
= pcall( wez.mux.get_pane, pane_id )
354 - if not ok_pane
or not mux_pane
then return nil end 356 - local ok_info, info
= pcall( mux_pane.get_foreground_process_info, mux_pane )
357 - if not ok_info
or not info
then return nil end 359 - return detect_from_process_info( info )
362 -local tab_title = function ( tab )
363 - local explicit_title
= apps.clean_title( tab.tab_title )
364 - local pane_title
= apps.clean_title( tab.active_pane.title )
365 - local display_title
= explicit_title
or pane_title
366 - local vars
= tab.active_pane.user_vars
or {}
368 - local detected
= root_or_nil( apps.detect_from_commandline( vars.WEZTERM_PROG ) )
369 - or process_info_program( tab )
370 - or root_or_nil( tab.active_pane.foreground_process_name )
371 - or title_program( display_title )
372 - or FALLBACK_TAB_PROGRAM
374 - local detail
= title_detail( display_title, detected, explicit_title
~= nil )
375 - return tab_label( detected, detail ), program_icon( detected ), detected
378 -local tab_colors = function ( tab, hover )
379 - if tab.is_active
then return palette.ui.focus, palette.content.backdrop
end 380 - if hover
then return palette.ui.accent, palette.content.backdrop
end 381 - if tab.is_last_active
then return palette.ui.backdrop, palette.ui.important_local
end 382 - return palette.ui.backdrop, palette.content.normal
385 -local tab_state_badge = function ( tab )
386 - local badge, color
= user_state_badge( tab.active_pane.user_vars )
387 - if badge
then return badge, color
end 389 - local has_progress, progress
= pcall(
function ()
return tab.active_pane.progress
end )
390 - badge, color
= progress_badge( has_progress
and progress
or 0 )
391 - if badge
then return badge, color
end 393 - local id
= tab.tab_id
or tab.tab_index
394 - badge, color
= activity_badge( tab.active_pane.title )
396 - tab_activity_until[id]
= wall_seconds()
+ 2.0 397 - return badge, color
400 - for _, pane_info
in ipairs( tab.panes
or {} )
do 401 - if pane_info.has_unseen_output
then 402 - tab_activity_until[id]
= wall_seconds()
+ 2.0 403 - return busy_badge()
406 - if tab_activity_until[id]
and tab_activity_until[id]
> wall_seconds()
then 407 - return busy_badge()
409 - tab_activity_until[id]
= nil 80 +local domain_label = function ( domain )
81 + if not domain
or domain
== 'local' or domain
== 'Local' then return host_domain()
end 82 + if domain:find(
'^WSL:',
1,
false )
then return 'WSL', wez.nerdfonts.dev_linux
or '□', palette.ui.important_local
end 83 + if domain:find(
'^scope:',
1,
false )
then return 'EXE', wez.nerdfonts.cod_gear
or '□', palette.warning
end 84 + return ( domain:upper():gsub(
'[^%w]',
'' ):sub(
1,
3 )
.. 'LOC' ):sub(
1,
3 ), wez.nerdfonts.cod_terminal
or '□', palette.ui.important_local
413 87 wez.on(
'format-tab-title',
function ( tab, tabs, panes, config, hover, max_width )
414 88 if config
then use_palette_for_scheme( config.color_scheme )
end 415 - local title, icon
= tab_title( tab )
416 - local state_badge, state_badge_color
= tab_state_badge( tab )
417 - local bg, fg
= tab_colors( tab, hover )
418 - local bar_bg
= palette.content.backdrop
419 - local shadow
= tab.is_active
and palette.ui.accent
or palette.content.backdrop
420 - local left_sep
= wez.nerdfonts.ple_left_half_circle_thick
or '\u{e0b4}' 421 - local right_sep
= wez.nerdfonts.ple_right_half_circle_thick
or '\u{e0b6}' 422 - local dot
= tab.is_active
and '●' or '○' 423 - local chrome_width
= 8 424 - local budget
= math.
max(
1, max_width
- chrome_width )
425 - local text
= wez.truncate_right(
string.
format(
' %s %d %s %s', dot, tab.tab_index
+ 1, icon, title ), budget )
428 - {
Background = {
Color = bar_bg } },
429 - {
Foreground = {
Color = shadow } },
431 - {
Foreground = {
Color = bg } },
432 - {
Text = left_sep },
90 + local bg
= palette.content.backdrop
91 + local fg
= palette.content.minor
92 + if tab.is_active
then 93 + bg
= palette.ui.focus
94 + fg
= palette.content.backdrop
96 + bg
= palette.ui.accent
97 + fg
= palette.content.backdrop
100 + local marker
= tab.is_active
and '●' or '○' 101 + local title
= tab_text( tab )
102 + local label
= string.
format(
' %s %d %s ', marker, tab.tab_index
+ 1, title )
103 + label
= wez.truncate_right( label,
math.
max(
1, max_width
or 32 ) )
433 106 {
Background = {
Color = bg } },
434 107 {
Foreground = {
Color = fg } },
435 108 {
Attribute = {
Intensity = tab.is_active
and 'Bold' or 'Normal' } },
438 - fixed_badge( elements, state_badge, state_badge_color, fg )
439 - table.
insert( elements, {
Text =
' ' } )
440 - table.
insert( elements, {
Background = {
Color = bar_bg } } )
441 - table.
insert( elements, {
Foreground = {
Color = bg } } )
442 - table.
insert( elements, {
Text = right_sep } )
443 - table.
insert( elements, {
Foreground = {
Color = shadow } } )
444 - table.
insert( elements, {
Text =
' ' } )
445 - table.
insert( elements, {
Attribute = {
Intensity =
'Normal' } } )
449 -wez.on(
'format-window-title',
function ( tab, pane, tabs, panes, config )
114 +wez.on(
'format-window-title',
function ( tab )
450 115 local ok, workspace
= pcall( wez.mux.get_active_workspace )
451 116 workspace
= ok
and workspace
or 'default' 452 - local title
= tab
and tab_title( tab )
or 'WezTerm' 117 + local title
= tab
and tab_text( tab )
or 'WezTerm' 453 118 return '[' .. workspace
.. '] ' .. title
457 121 wez.on(
'update-status',
function ( window, pane )
458 122 local ok_status, status_error
= pcall(
function ()
459 - use_palette_for_window( window )
460 - local key_table
= window:active_key_table()
461 - local current_workspace
= window:active_workspace()
462 - local zoomed_state_ok, zoomed_state
= pcall( zoomed, pane )
463 - zoomed_state
= zoomed_state_ok
and zoomed_state
or nil 465 - if window:leader_is_active()
then 468 - local pane_domain_ok, pane_domain
= pcall( pane.get_domain_name, pane )
469 - if not pane_domain_ok
then return end 123 + use_palette_for_window( window )
126 + local key_table
= window:active_key_table()
127 + if window:leader_is_active()
then key_table
= 'LEADER' end 130 + {
Background = {
Color = palette.error } },
131 + {
Foreground = {
Color = palette.ui.backdrop } },
132 + {
Attribute = {
Intensity =
'Bold' } },
133 + {
Text =
' ' .. key_table
.. ' ' },
473 - if zoomed_state
then 474 - table.
insert( status, zoomed_state )
139 + local ok_zoom, zoomed_state
= pcall( zoomed, pane )
140 + if ok_zoom
and zoomed_state
then 141 + table.
insert( right, {
Foreground = {
Color = palette.ui.minor } } )
142 + table.
insert( right, {
Text = zoomed_state
.. ' ' } )
144 + window:set_right_status( wez.format( right ) )
477 - local status_parts
= {}
478 - for _, value
in ipairs( status )
do 479 - if value
and value
~= '' then table.
insert( status_parts, value )
end 146 + local battery
= bat.get_battery_icons()
147 + if battery
~= '' then battery
= battery
.. ' ' end 482 - local right_elements
= {}
483 - if key_table
or leader
then 484 - local mode_text
= key_table
or 'LEADER' 486 - {
Background = {
Color = palette.error } },
487 - {
Foreground = {
Color = palette.ui.backdrop } },
149 + local ok_domain, domain
= pcall( pane.get_domain_name, pane )
150 + local domain_text, domain_icon, domain_color
= domain_label( ok_domain
and domain
or nil )
151 + local workspace
= short_workspace( window:active_workspace() )
153 + window:set_left_status( wez.format {
154 + {
Text = battery },
155 + {
Foreground = {
Color = palette.ui.important_local } },
488 156 {
Attribute = {
Intensity =
'Bold' } },
489 - {
Text =
' ' .. mode_text
.. ' ' },
157 + {
Text =
'● ' .. workspace
.. ' ' },
158 + {
Foreground = {
Color = domain_color } },
159 + {
Text = domain_icon
.. ' ' .. domain_text
.. ' ' },
490 160 'ResetAttributes',
495 - local status_text
= table.
concat( status_parts, DELIMITER )
496 - if status_text
~= '' then 497 - table.
insert( right_elements, {
Foreground = {
Color = palette.ui.minor } } )
498 - table.
insert( right_elements, {
Text = status_text
.. ' ' } )
501 - window:set_right_status( wez.format( right_elements ) )
502 - local battery_icons
= bat.get_battery_icons()
503 - if battery_icons
~= '' then 504 - battery_icons
= battery_icons
.. ' ' 507 - local left_elements
= {
508 - {
Text = battery_icons },
510 - for _, element
in ipairs( workspace_hud( current_workspace ) )
do 511 - table.
insert( left_elements, element )
513 - for _, element
in ipairs( domain_hud( pane_domain ) )
do 514 - table.
insert( left_elements, element )
517 - window:set_left_status( wez.format( left_elements ) )
520 164 if not ok_status
then 529 173 return function ( cfg )
530 174 cfg.enable_tab_bar
= true 532 175 cfg.hide_tab_bar_if_only_one_tab
= false 533 176 cfg.use_fancy_tab_bar
= false 534 - cfg.tab_max_width
= 172 177 + cfg.tab_max_width
= 64 535 178 cfg.show_tabs_in_tab_bar
= true 536 179 cfg.show_new_tab_button_in_tab_bar
= false 537 180 cfg.tab_bar_at_bottom
= true