repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

ui(wezterm): show workspace status

0c49140c9ce36d919c0f25d503df7685f1e882e3

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (4)

+253 / −27 text lines

Diff layout

wezterm/bugabinga/options.lua

Modified

+1 / −0 text lines

99 cfg.check_for_updates = false
1010 cfg.enable_kitty_keyboard = not wez.target_triple:match 'win'
1111 cfg.audible_bell = 'Disabled'
12 cfg.notification_handling = 'AlwaysShow'
1213 cfg.visual_bell = {
1314 fade_in_duration_ms = 69,
1415 fade_out_duration_ms = 69,

wezterm/bugabinga/status.lua

Modified

+251 / −24 text lines

44local DELIMITER = ' · '
55local ai_shell = require 'bugabinga.ai_shell'
66local palette = require 'bugabinga.nugu.palette_dark'.palette
7local icon_names = require 'bugabinga.icons'
89local zoomed = function ( pane )
910 local tab = pane:tab()
1819 return any_is_zoomed and '🔎 Zoomed Pane' or nil
1920end
21-- Detect special foreground programs via pane title
22-- (get_foreground_process_info returns nil on this system)
23local detect_program = function ( pane )
22local basename = function ( value )
23 if not value or value == '' then return nil end
24 value = value:gsub( '\\', '/' )
25 return value:match( '([^/]+)$' ) or value
26end
28local 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 )
32end
34local 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
42 return program
43end
45local safe_user_vars = function ( pane )
46 local ok, vars = pcall( pane.get_user_vars, pane )
47 if ok and vars then return vars end
48 return {}
49end
51local safe_title = function ( pane )
2452 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
2754 return nil
2855end
57local 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',
64 } do
65 if lower:find( program, 1, true ) then return program end
66 end
67 return nil
68end
70local 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 ) )
75end
77local 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]
81 end
82 return ''
83end
85local 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 )
89 end
90 if #name > 28 then
91 return '…/' .. (basename( name ) or name)
92 end
93 return name
94end
96local 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
103 return nil
104end
106local 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
118 end
119 summary.windows = summary.windows + 1
121 local ok_tabs, tabs = pcall( function () return mux_window:tabs() end )
122 if ok_tabs then
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 )
126 if ok_panes then
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 )
131 if class then
132 summary.programs[class] = (summary.programs[class] or 0) + 1
133 end
134 end
135 end
136 end
137 end
138 end
139 end
141 return summaries
142end
144local append_count = function ( parts, icon, count )
145 if count and count > 0 then
146 table.insert( parts, icon .. (count > 1 and tostring( count ) or '') )
147 end
148end
150local 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' )
161 end
163 return table.concat( parts, ' ' )
164end
166local workspace_hud = function ( active_workspace )
167 local summaries = workspace_summaries()
168 local names = {}
169 for name in pairs( summaries ) do table.insert( names, name ) end
170 table.sort( names )
172 local ordered = {}
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
176 end
178 local elements = {}
179 local shown = 0
180 for _, name in ipairs( ordered ) do
181 shown = shown + 1
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' } } )
189 end
191 if #ordered > 5 then
192 table.insert( elements, { Foreground = { Color = palette.ui.minor } } )
193 table.insert( elements, { Text = ' +' .. tostring( #ordered - 5 ) } )
194 end
196 return elements
197end
199local 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 )
203 end
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 )
208 or 'nu'
209 return program, program_icon( program )
210end
212wez.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
218 break
219 end
220 end
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
230 elseif hover then
231 bg = palette.ui.accent
232 fg = palette.ui.backdrop
233 elseif tab.is_last_active then
234 fg = palette.ui.important_local
235 else
236 fg = palette.ui.minor
237 end
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 ) )
243 return {
244 { Background = { Color = bg } },
245 { Foreground = { Color = fg } },
246 { Text = text },
247 }
248end )
250wez.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
255end )
30257-- Show which key table is active in the status area
31258wez.on( 'update-status', function ( window, pane )
32259 local key_table = window:active_key_table()
33260 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 )
35262 zoomed_state = zoomed_state_ok and zoomed_state or nil
36263 local leader = nil
37264 if window:leader_is_active() then
38265 leader = '󱁐 '
39266 end
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 )
41268 if not pane_domain_ok then return end
43 local os_icon = wez.target_triple:find 'windows' and ' ' or ' '
44270 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, }
48274 -- Special program indicators
49275 local prog = detect_program( pane )
53279 { Attribute = { Intensity = 'Bold' } },
54280 { Text = 'pi' },
55281 } )
282 elseif prog and prog ~= 'nu' then
283 table.insert( status, program_icon( prog ) .. ' ' .. prog )
56284 end
58286 if key_table then
62290 table.insert( status, zoomed_state )
63291 end
65 local context = wez.format {
66 { Text = current_workspace, },
67 { Text = '@', },
68 { Attribute = { Intensity = 'Bold', }, },
69 { Text = pane_domain, },
70 }
71 table.insert( status, context )
293 if pane_domain and pane_domain ~= 'local' and pane_domain ~= 'Local' then
294 table.insert( status, '@' .. pane_domain )
295 end
73297 local right_elements = {
74298 { Text = table.concat( status, DELIMITER ), },
86310 battery_icons = battery_icons .. ' '
87311 end
89 window:set_left_status(
90 wez.format {
91 { Text = '  ', },
92 { Text = battery_icons, },
93 }
94 )
313 local left_elements = {
314 { Text = '  ' },
315 { Text = battery_icons },
316 }
317 for _, element in ipairs( workspace_hud( current_workspace ) ) do
318 table.insert( left_elements, element )
319 end
321 window:set_left_status( wez.format( left_elements ) )
95322end )
97324return function ( cfg )
99326 -- if this is hidden, we cannot see the right status are
100327 cfg.hide_tab_bar_if_only_one_tab = false
101328 cfg.use_fancy_tab_bar = false
102 cfg.tab_max_width = 42
329 cfg.tab_max_width = 32
103330 cfg.tab_bar_at_bottom = true
104331 cfg.status_update_interval = 1000
105332end

wezterm/bugabinga/window.lua

Modified

+0 / −2 text lines

2121 top = 0,
2222 bottom = 0,
2323 }
25 cfg.tab_max_width = 24
2624end

wezterm/bugabinga/workspace_switcher.lua

Modified

+1 / −1 text lines

5757local function get_choices()
5858 local choices = {}
59 local workspace_ids = get_workspace_elements( choices )
59 local _, workspace_ids = get_workspace_elements( choices )
6060 get_zoxide_elements( choices, workspace_ids )
6161 return choices
6262end