repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

fix wezterm tab app detection

77b4354c7cea9335c899c10bc59c11ebcab17997

Oliver Krylow <o.krylow@isp-insoft.de> ·

unsigned

Browse filesCompare with HEAD

Simplify tab app detection so command lines and task titles do not classify from arbitrary words. Fix Nushell WEZTERM_PROG user-var emission.

Changed files (3)

+49 / −89 text lines

Diff layout

nushell/modules/wezterm_integration.nu

Modified

+1 / −1 text lines

2020export-env {
2121 def __wezterm_set_user_var [name: string, value: string] {
2222 let b64 = ($value | encode base64)
23 let osc = (ansi --osc $"1337;SetUserVar=($name)=($b64)=")
23 let osc = (ansi --osc $"1337;SetUserVar=($name)=($b64)")
2424 print -n ($osc + (char bel))
2525 }

wezterm/bugabinga/apps.lua

Modified

+2 / −5 text lines

138138 commandline = M.clean_title(commandline)
139139 if not commandline then return nil end
141 local lower = commandline:lower()
142 for _, program in ipairs(TITLE_ORDER) do
143 if title_contains_program(lower, program) then return M.normalize(program) end
144 end
141 -- Command lines are arbitrary user text. Trust only argv[0]; never classify
142 -- from arguments like `rg claude` or task text like `Fix Claude settings`.
146143 return M.normalize(M.first_command(commandline))
147144end

wezterm/bugabinga/status.lua

Modified

+46 / −83 text lines

88package.loaded['bugabinga.apps'] = nil
99local apps = require 'bugabinga.apps'
11local MAX_TAB_LABEL_WIDTH = 172
11local FALLBACK_TAB_PROGRAM = 'nu'
1212local WORKSPACE_SUMMARY_TTL_SECONDS = 2.0
1313local PALETTE_REFRESH_TTL_SECONDS = 2.0
262262end
264264local domain_hud = function ( domain )
265 if not domain or domain == 'local' or domain == 'Local' then return {} end
265 local label = domain or 'local'
267266 local color = palette.ui.important_local
268 if domain:find( '^scope:', 1, false ) then color = palette.warning end
268 if not domain or domain == 'local' or domain == 'Local' then
269 label = 'WIN'
270 color = palette.warning
271 elseif domain:find( '^WSL:', 1, false ) then
272 label = domain:gsub( '^WSL:', 'WSL ' )
273 elseif domain:find( '^scope:', 1, false ) then
274 color = palette.warning
275 end
270277 return {
271278 { Foreground = { Color = color } },
272279 { Attribute = { Intensity = 'Bold' } },
273 { Text = '@' .. domain .. ' ' },
280 { Text = '@' .. label .. ' ' },
274281 { Attribute = { Intensity = 'Normal' } },
275282 }
276283end
278local tab_label = function ( program, detail, max_width )
279 program = apps.normalize( program ) or 'nu'
280 local base = apps.label( program ) or apps.label( 'nu' )
281 local label = detail and (base .. ' · ' .. detail) or base
282 return wez.truncate_right( label, max_width or MAX_TAB_LABEL_WIDTH )
285local root_or_nil = function ( program )
286 program = apps.normalize( program )
287 if apps.is_root( program ) then return program end
288 return nil
283289end
285local collapse_duplicate_suffix = function ( title )
286 local head, tail = title:match( '^(.*)%s+[-–—:]%s+(.+)$' )
287 if not head or not tail then return title end
291local tab_label = function ( program, detail )
292 program = root_or_nil( program ) or FALLBACK_TAB_PROGRAM
293 local base = apps.label( program ) or apps.label( FALLBACK_TAB_PROGRAM )
294 return detail and (base .. ' · ' .. detail) or base
295end
289 local compact_head = head:lower():gsub( '[^%w]', '' )
290 local compact_tail = tail:lower():gsub( '[^%w]', '' )
291 if compact_tail ~= '' and compact_head == compact_tail then return head end
292 return title
297local title_program = function ( title )
298 title = strip_activity_marker( title )
299 if not title then return nil end
300 if title:sub( 1, #'π' ) == 'π' then return 'pi' end
302 -- Titles are prose while agents run. Trust only a leading app token; never
303 -- classify from words inside task text like "Fix Claude settings".
304 return root_or_nil( title:match( '^([%w%._%-]+)' ) )
293305end
295307local title_detail = function ( title, program, include_shell_titles )
296308 title = strip_activity_marker( title )
297309 if not title then return nil end
299 -- Keep OSC titles visible. Only strip generic app prefixes/spinner frames and
300 -- exact duplicate suffixes; do not special-case current task/window names.
301311 local detail = apps.title_detail( title, program, include_shell_titles ) or title
302312 detail = strip_activity_marker( detail )
303 detail = collapse_duplicate_suffix( detail )
304313 detail = apps.clean_title( detail )
305314 if not detail or apps.normalize( detail ) == apps.normalize( program ) then return nil end
306315 return detail
312321 visit = function ( node )
313322 if detected or type( node ) ~= 'table' then return end
315 local tokens = {}
316324 for _, key in ipairs { 'name', 'executable' } do
317 if node[key] then table.insert( tokens, tostring( node[key] ) ) end
325 detected = detected or root_or_nil( node[key] )
318326 end
319327 if type( node.argv ) == 'table' then
320 for _, arg in ipairs( node.argv ) do table.insert( tokens, tostring( arg ) ) end
321 end
323 for _, token in ipairs( tokens ) do
324 local normalized = apps.normalize( token )
325 if apps.is_root( normalized ) then
326 detected = normalized
327 return
328 end
330 -- Only match substrings inside path-like tokens, never arbitrary task text.
331 local lower = token:lower()
332 if lower:find( '/', 1, true ) or lower:find( '\\', 1, true ) then
333 for _, program in ipairs { 'codex', 'claude', 'opencode', 'pi' } do
334 if lower:find( program, 1, true ) then
335 detected = program
336 return
337 end
338 end
328 for _, arg in ipairs( node.argv ) do
329 detected = detected or root_or_nil( arg )
339330 end
340331 end
332 if detected then return end
342334 if type( node.children ) == 'table' then
343335 for _, child in pairs( node.children ) do visit( child ) end
347339 return detected
348340end
350local strong_title_program = function ( title )
351 title = apps.clean_title( title )
352 if not title then return nil, false end
354 if title:sub( 1, #'π' ) == 'π' then return 'pi', false end
356 local _, had_marker = strip_activity_marker( title )
357 if had_marker then return 'claude', true end
359 return nil, false
360end
362342local process_info_program = function ( tab )
363343 local pane_id = tab.active_pane and tab.active_pane.pane_id
364344 if not pane_id then return nil end
369349 local ok_info, info = pcall( mux_pane.get_foreground_process_info, mux_pane )
370350 if not ok_info or not info then return nil end
372 local program = detect_from_process_info( info )
373 if apps.is_root( program ) then return program end
374 return nil
352 return detect_from_process_info( info )
375353end
377355local tab_title = function ( tab )
378356 local id = tab.tab_id or tab.tab_index
379357 local explicit_title = apps.clean_title( tab.tab_title )
380358 local pane_title = apps.clean_title( tab.active_pane.title )
359 local display_title = explicit_title or pane_title
381360 local vars = tab.active_pane.user_vars or {}
382 local clean_pane_title = strip_activity_marker( pane_title )
383 local clean_explicit_title = strip_activity_marker( explicit_title )
384 local from_command = apps.detect_from_commandline( vars.WEZTERM_PROG )
385 local from_info = process_info_program( tab )
386 local from_process = apps.normalize( tab.active_pane.foreground_process_name )
387 if not apps.is_root( from_process ) then from_process = nil end
388 local from_explicit_title, explicit_weak = strong_title_program( explicit_title )
389 local from_pane_title, pane_weak = strong_title_program( pane_title )
390 local from_title = from_explicit_title or from_pane_title
391 local weak_title = (from_explicit_title and explicit_weak) or (not from_explicit_title and pane_weak)
392 local detected = (apps.is_root( from_command ) and from_command)
393 or from_info
394 or from_process
395 or (not weak_title and apps.is_root( from_title ) and from_title)
396 or (apps.is_root( from_title ) and from_title)
397 or 'nu'
399 -- Terminal/agent titles are volatile during activity. Cache one stable app label
400 -- per tab and only upgrade from generic shell to a real root app.
401 local cached = stable_tab_programs[id]
402 if not cached or (detected ~= 'nu' and detected ~= cached) then
403 cached = detected
404 stable_tab_programs[id] = cached
405 end
362 local detected = root_or_nil( apps.detect_from_commandline( vars.WEZTERM_PROG ) )
363 or process_info_program( tab )
364 or root_or_nil( tab.active_pane.foreground_process_name )
365 or title_program( display_title )
366 or stable_tab_programs[id]
367 or FALLBACK_TAB_PROGRAM
407 local detail = title_detail( clean_explicit_title or clean_pane_title, cached, explicit_title ~= nil )
369 if detected ~= FALLBACK_TAB_PROGRAM then stable_tab_programs[id] = detected end
409 local label = tab_label( cached, detail, MAX_TAB_LABEL_WIDTH )
410 return label, program_icon( cached ), cached
371 local detail = title_detail( display_title, detected, explicit_title ~= nil )
372 return tab_label( detected, detail ), program_icon( detected ), detected
411373end
413375local tab_colors = function ( tab, hover )
454416 local left_sep = wez.nerdfonts.ple_left_half_circle_thick or '\u{e0b4}'
455417 local right_sep = wez.nerdfonts.ple_right_half_circle_thick or '\u{e0b6}'
456418 local dot = tab.is_active and '●' or '○'
457 local budget = math.max( 1, max_width - 10 )
419 local chrome_width = 8 -- separators, padding, fixed state-badge slot
420 local budget = math.max( 1, max_width - chrome_width )
458421 local text = wez.truncate_right( string.format( ' %s %d %s %s', dot, tab.tab_index + 1, icon, title ), budget )
460423 local elements = {