4 4 local wez
= require 'wezterm' 5 5 local bat
= require 'bugabinga.battery' 7 7 local DELIMITER
= ' ยท ' 8 8 local ai_shell
= require 'bugabinga.ai_shell' 9 9 local palette
= require 'bugabinga.nugu.palette_dark'.palette
10 +local icon_names
= require 'bugabinga.icons' 11 12 local zoomed = function ( pane )
12 13 local tab
= pane:tab()
18 19 return any_is_zoomed
and '๐ Zoomed Pane' or nil 23 -local detect_program = function ( pane )
22 +local basename = function ( value )
23 + if not value
or value
== '' then return nil end 24 + value
= value:gsub(
'\\',
'/' )
25 + return value:match(
'([^/]+)$' )
or value
28 +local first_command = function ( commandline )
29 + if not commandline
or commandline
== '' then return nil end 30 + local token
= commandline:match(
'^%s*([^%s|;&]+)' )
31 + return basename( token )
34 +local normalize_program = function ( program )
35 + program
= basename( program )
36 + if not program
then return nil end 37 + program
= program:lower()
38 + if program
== 'vim.opti' then return 'vim' end 39 + if program
== 'node.opti' then return 'node' end 40 + if program:find(
'^python' )
then return 'python' end 41 + if program
== 'lazygit' then return 'git' end 45 +local safe_user_vars = function ( pane )
46 + local ok, vars
= pcall( pane.get_user_vars, pane )
47 + if ok
and vars
then return vars
end 51 +local safe_title = function ( pane )
24 52 local ok, title
= pcall( pane.get_title, pane )
25 - if not ok
or not title
then return nil end 26 - if title:find(
'ฯ' )
then return 'pi' end 53 + if ok
then return title
end 57 +local detect_program_from_title = function ( title )
58 + if not title
then return nil end 59 + local lower
= title:lower()
60 + if title:find(
'ฯ' )
or lower:find(
'%f[%w]pi%f[%W]' )
then return 'pi' end 61 + for _, program
in ipairs {
62 + 'nvim',
'vim',
'git',
'gh',
'yazi',
'aerc',
'weechat',
'cmus',
63 + 'wthrr',
'btm',
'top',
'nu',
'bash',
65 + if lower:find( program,
1,
true )
then return program
end 70 +local detect_program = function ( pane )
71 + local vars
= safe_user_vars( pane )
72 + local from_command
= normalize_program( first_command( vars.WEZTERM_PROG ) )
73 + if from_command
then return from_command
end 74 + return detect_program_from_title( safe_title( pane ) )
77 +local program_icon = function ( program )
78 + local icon_name
= icon_names[program]
79 + if icon_name
and wez.nerdfonts[icon_name]
then 80 + return wez.nerdfonts[icon_name]
85 +local short_workspace = function ( name )
86 + local home
= wez.home_dir
87 + if home
and name:sub(
1,
#home )
== home
then 88 + name
= '~' .. name:sub(
#home
+ 1 )
91 + return 'โฆ/' .. (basename( name )
or name)
96 +local classify_workspace_program = function ( program )
97 + if program
== 'pi' then return 'pi' end 98 + if program
== 'nvim' or program
== 'vim' then return 'nvim' end 99 + if program
== 'git' or program
== 'gh' then return 'git' end 100 + if program
== 'yazi' or program
== 'ranger' or program
== 'lf' then return 'files' end 101 + if program
== 'aerc' or program
== 'neomutt' then return 'mail' end 102 + if program
== 'wthrr' then return 'weather' end 106 +local workspace_summaries = function ()
107 + local ok, mux_windows
= pcall( wez.mux.all_windows )
108 + if not ok
then return {}
end 110 + local summaries
= {}
111 + for _, mux_window
in ipairs( mux_windows )
do 112 + local ok_workspace, workspace
= pcall(
function ()
return mux_window:get_workspace()
end )
113 + if ok_workspace
and workspace
then 114 + local summary
= summaries[workspace]
115 + if not summary
then 116 + summary
= {
name = workspace,
windows =
0,
tabs =
0,
panes =
0,
programs = {} }
117 + summaries[workspace]
= summary
119 + summary.windows
= summary.windows
+ 1 121 + local ok_tabs, tabs
= pcall(
function ()
return mux_window:tabs()
end )
123 + for _, tab
in ipairs( tabs )
do 124 + summary.tabs
= summary.tabs
+ 1 125 + local ok_panes, panes
= pcall(
function ()
return tab:panes_with_info()
end )
127 + for _, info
in ipairs( panes )
do 128 + summary.panes
= summary.panes
+ 1 129 + local program
= detect_program( info.pane )
130 + local class
= classify_workspace_program( program )
132 + summary.programs[class]
= (summary.programs[class]
or 0)
+ 1 144 +local append_count = function ( parts, icon, count )
145 + if count
and count
> 0 then 146 + table.
insert( parts, icon
.. (count
> 1 and tostring( count )
or '') )
150 +local workspace_badge = function ( summary, active )
151 + local parts
= { short_workspace( summary.name ) }
152 + append_count( parts,
'ฯ', summary.programs.pi )
153 + append_count( parts,
'๎
', summary.programs.nvim )
154 + append_count( parts,
'๎', summary.programs.git )
155 + append_count( parts,
'๏ป', summary.programs.files )
156 + append_count( parts,
'๓ฐฎ', summary.programs.mail )
157 + append_count( parts,
'๓ฐ', summary.programs.weather )
159 + if #parts
== 1 and active
and summary.tabs
> 1 then 160 + table.
insert( parts,
tostring( summary.tabs )
.. 't' )
163 + return table.
concat( parts,
' ' )
166 +local workspace_hud = function ( active_workspace )
167 + local summaries
= workspace_summaries()
169 + for name
in pairs( summaries )
do table.
insert( names, name )
end 170 + table.
sort( names )
173 + if summaries[active_workspace]
then table.
insert( ordered, active_workspace )
end 174 + for _, name
in ipairs( names )
do 175 + if name
~= active_workspace
then table.
insert( ordered, name )
end 178 + local elements
= {}
180 + for _, name
in ipairs( ordered )
do 182 + if shown
> 5 then break end 184 + local active
= name
== active_workspace
185 + table.
insert( elements, {
Foreground = {
Color = active
and palette.ui.important_local
or palette.ui.minor } } )
186 + if active
then table.
insert( elements, {
Attribute = {
Intensity =
'Bold' } } )
end 187 + table.
insert( elements, {
Text = (active
and ' โ ' or ' โ ')
.. workspace_badge( summaries[name], active ) } )
188 + table.
insert( elements, {
Attribute = {
Intensity =
'Normal' } } )
191 + if #ordered
> 5 then 192 + table.
insert( elements, {
Foreground = {
Color = palette.ui.minor } } )
193 + table.
insert( elements, {
Text =
' +' .. tostring(
#ordered
- 5 ) } )
199 +local tab_title = function ( tab )
200 + if tab.tab_title
and #tab.tab_title
> 0 then 201 + local explicit_program
= detect_program_from_title( tab.tab_title )
202 + return tab.tab_title, program_icon( explicit_program )
204 + local vars
= tab.active_pane.user_vars
or {}
205 + local program
= normalize_program( first_command( vars.WEZTERM_PROG ) )
206 + or detect_program_from_title( tab.active_pane.title )
207 + or normalize_program( tab.active_pane.foreground_process_name )
209 + return program, program_icon( program )
212 +wez.on(
'format-tab-title',
function ( tab, tabs, panes, config, hover, max_width )
213 + local title, icon
= tab_title( tab )
214 + local has_unseen_output
= false 215 + for _, pane_info
in ipairs( tab.panes
or {} )
do 216 + if pane_info.has_unseen_output
then 217 + has_unseen_output
= true 222 + local bg
= palette.ui.backdrop
223 + local fg
= palette.ui.normal
224 + if tab.is_active
then 225 + bg
= palette.ui.focus
226 + fg
= palette.ui.backdrop
227 + elseif has_unseen_output
then 228 + bg
= palette.warning
229 + fg
= palette.content.backdrop
231 + bg
= palette.ui.accent
232 + fg
= palette.ui.backdrop
233 + elseif tab.is_last_active
then 234 + fg
= palette.ui.important_local
236 + fg
= palette.ui.minor
239 + local suffix
= has_unseen_output
and ' !' or '' 240 + local text
= string.
format(
' %d %s %s%s ', tab.tab_index
+ 1, icon, title, suffix )
241 + text
= wez.truncate_right( text,
math.
max(
1, max_width ) )
244 + {
Background = {
Color = bg } },
245 + {
Foreground = {
Color = fg } },
250 +wez.on(
'format-window-title',
function ( tab, pane, tabs, panes, config )
251 + local ok, workspace
= pcall( wez.mux.get_active_workspace )
252 + workspace
= ok
and workspace
or 'default' 253 + local title
= pane
and pane.title
or tab.active_pane.title
254 + return '[' .. workspace
.. '] ' .. title
31 258 wez.on(
'update-status',
function ( window, pane )
32 259 local key_table
= window:active_key_table()
33 260 local current_workspace
= window:active_workspace()
34 - local zoomed_state_ok, zoomed_state
= pcall(zoomed, pane)
261 + local zoomed_state_ok, zoomed_state
= pcall( zoomed, pane )
35 262 zoomed_state
= zoomed_state_ok
and zoomed_state
or nil 36 263 local leader
= nil 37 264 if window:leader_is_active()
then 40 - local pane_domain_ok, pane_domain
= pcall(pane.get_domain_name, pane)
267 + local pane_domain_ok, pane_domain
= pcall( pane.get_domain_name, pane )
41 268 if not pane_domain_ok
then return end 43 - local os_icon
= wez.target_triple:find
'windows' and '๎ ' or '๎ฏ ' 44 270 local time
= wez.time.now():format
'%H:%M' 45 - local ai_status
= ai_shell.get_status(window)
46 - local status
= { time, os_icon, ai_status, leader, }
271 + local ai_status
= ai_shell.get_status( window )
272 + local status
= { time, ai_status, leader, }
49 275 local prog
= detect_program( pane )
53 279 {
Attribute = {
Intensity =
'Bold' } },
282 + elseif prog
and prog
~= 'nu' then
283 + table.
insert( status, program_icon( prog )
.. ' ' .. prog )
62 290 table.
insert( status, zoomed_state )
65 - local context
= wez.format {
66 - {
Text = current_workspace, },
68 - {
Attribute = {
Intensity =
'Bold', }, },
69 - {
Text = pane_domain, },
71 - table.
insert( status, context )
293 + if pane_domain
and pane_domain
~= 'local' and pane_domain
~= 'Local' then 294 + table.
insert( status,
'@' .. pane_domain )
73 297 local right_elements
= {
74 298 {
Text =
table.
concat( status, DELIMITER ), },
86 310 battery_icons
= battery_icons
.. ' ' 89 - window:set_left_status(
91 - {
Text =
' ๎ข ', },
92 - {
Text = battery_icons, },
313 + local left_elements
= {
314 + {
Text =
' ๎ข ' },
315 + {
Text = battery_icons },
317 + for _, element
in ipairs( workspace_hud( current_workspace ) )
do 318 + table.
insert( left_elements, element )
321 + window:set_left_status( wez.format( left_elements ) )
97 324 return function ( cfg )
100 327 cfg.hide_tab_bar_if_only_one_tab
= false 101 328 cfg.use_fancy_tab_bar
= false 102 - cfg.tab_max_width
= 42 329 + cfg.tab_max_width
= 32 103 330 cfg.tab_bar_at_bottom
= true 104 331 cfg.status_update_interval
= 1000