repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

ui(wezterm): show workspace status

a25ca24c7d176a59da581854e655aa86d2360b0d

Oliver Jan Krylow <oliver@bugabinga.net> ยท

unsigned

Browse filesCompare with HEAD

Changed files (4)

wezterm/bugabinga/options.lua

Modified
9 9 cfg.check_for_updates = false
10 10 cfg.enable_kitty_keyboard = not wez.target_triple:match 'win'
11 11 cfg.audible_bell = 'Disabled'
12 + cfg.notification_handling = 'AlwaysShow'
12 13 cfg.visual_bell = {
13 14 fade_in_duration_ms = 69,
14 15 fade_out_duration_ms = 69,

wezterm/bugabinga/status.lua

Modified
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
21 --- Detect special foreground programs via pane title
22 --- (get_foreground_process_info returns nil on this system)
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
26 +end
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 )
32 +end
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
42 + return program
43 +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
48 + return {}
49 +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
27 54 return nil
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',
64 + } do
65 + if lower:find( program, 1, true ) then return program end
66 + end
67 + return nil
68 +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 ) )
75 +end
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]
81 + end
82 + return '๏’‰'
83 +end
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 )
89 + end
90 + if #name > 28 then
91 + return 'โ€ฆ/' .. (basename( name ) or name)
92 + end
93 + return name
94 +end
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
103 + return nil
104 +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
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
142 +end
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 '') )
147 + end
148 +end
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' )
161 + end
163 + return table.concat( parts, ' ' )
164 +end
166 +local 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
197 +end
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 )
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 )
210 +end
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
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 },
248 +end )
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
255 +end )
30 257 -- Show which key table is active in the status area
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
38 265 leader = '๓ฑ '
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, }
48 274 -- Special program indicators
49 275 local prog = detect_program( pane )
53 279 { Attribute = { Intensity = 'Bold' } },
54 280 { Text = 'pi' },
282 + elseif prog and prog ~= 'nu' then
283 + table.insert( status, program_icon( prog ) .. ' ' .. prog )
58 286 if key_table then
62 290 table.insert( status, zoomed_state )
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
73 297 local right_elements = {
74 298 { Text = table.concat( status, DELIMITER ), },
86 310 battery_icons = battery_icons .. ' '
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 },
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 ) )
97 324 return function ( cfg )
99 326 -- if this is hidden, we cannot see the right status are
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

wezterm/bugabinga/window.lua

Modified
21 21 top = 0,
22 22 bottom = 0,
25 - cfg.tab_max_width = 24

wezterm/bugabinga/workspace_switcher.lua

Modified
57 57 local function get_choices()
58 58 local choices = {}
59 - local workspace_ids = get_workspace_elements( choices )
59 + local _, workspace_ids = get_workspace_elements( choices )
60 60 get_zoxide_elements( choices, workspace_ids )
61 61 return choices