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)
nushell/modules/wezterm_integration.nu
Modified+1 / −1 text lines
2020export-env {export-env { 2121 def __wezterm_set_user_var [name: string, value: string] { def __wezterm_set_user_var [name: string, value: string] { 2222 let b64 = ($value | encode base64) 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)) print -n ($osc + (char bel)) wezterm/bugabinga/apps.lua
Modified+2 / −5 text lines
138138 commandline = M.clean_title(commandline) commandline = M.clean_title(commandline) 139139 if not commandline then return nil end 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 146143 return M.normalize(M.first_command(commandline)) return M.normalize(M.first_command(commandline)) wezterm/bugabinga/status.lua
Modified+46 / −83 text lines
88package.loaded['bugabinga.apps'] = nilpackage.loaded['bugabinga.apps'] = nil 99local apps = require 'bugabinga.apps'local apps = require 'bugabinga.apps' 11-local MAX_TAB_LABEL_WIDTH = 172 11+local FALLBACK_TAB_PROGRAM = 'nu' 1212local WORKSPACE_SUMMARY_TTL_SECONDS = 2.0local WORKSPACE_SUMMARY_TTL_SECONDS = 2.0 1313local PALETTE_REFRESH_TTL_SECONDS = 2.0local PALETTE_REFRESH_TTL_SECONDS = 2.0 264264local domain_hud = function ( domain )local 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 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 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 271278 { Foreground = { Color = color } }, { Foreground = { Color = color } }, 272279 { Attribute = { Intensity = 'Bold' } }, { Attribute = { Intensity = 'Bold' } }, 273- { Text = '@' .. domain .. ' ' }, 280+ { Text = '@' .. label .. ' ' }, 274281 { Attribute = { Intensity = 'Normal' } }, { Attribute = { Intensity = 'Normal' } }, 278-local 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 ) 285+local root_or_nil = function ( program ) 286+ program = apps.normalize( program ) 287+ if apps.is_root( program ) then return program end 285-local collapse_duplicate_suffix = function ( title ) 286- local head, tail = title:match( '^(.*)%s+[-–—:]%s+(.+)$' ) 287- if not head or not tail then return title end 291+local 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 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 297+local 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 304+ return root_or_nil( title:match( '^([%w%._%-]+)' ) ) 295307local title_detail = function ( title, program, include_shell_titles )local title_detail = function ( title, program, include_shell_titles ) 296308 title = strip_activity_marker( title ) title = strip_activity_marker( title ) 297309 if not title then return nil end if not title then return nil end 301311 local detail = apps.title_detail( title, program, include_shell_titles ) or title local detail = apps.title_detail( title, program, include_shell_titles ) or title 302312 detail = strip_activity_marker( detail ) detail = strip_activity_marker( detail ) 303- detail = collapse_duplicate_suffix( detail ) 304313 detail = apps.clean_title( detail ) detail = apps.clean_title( detail ) 305314 if not detail or apps.normalize( detail ) == apps.normalize( program ) then return nil end if not detail or apps.normalize( detail ) == apps.normalize( program ) then return nil end 306315 return detail return detail 312321 visit = function ( node ) visit = function ( node ) 313322 if detected or type( node ) ~= 'table' then return end if detected or type( node ) ~= 'table' then return end 316324 for _, key in ipairs { 'name', 'executable' } do 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] ) 319327 if type( node.argv ) == 'table' then if type( node.argv ) == 'table' then 320- for _, arg in ipairs( node.argv ) do table.insert( tokens, tostring( arg ) ) end 323- for _, token in ipairs( tokens ) do 324- local normalized = apps.normalize( token ) 325- if apps.is_root( normalized ) then 326- detected = normalized 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 328+ for _, arg in ipairs( node.argv ) do 329+ detected = detected or root_or_nil( arg ) 332+ if detected then return end 342334 if type( node.children ) == 'table' then if type( node.children ) == 'table' then 343335 for _, child in pairs( node.children ) do visit( child ) end for _, child in pairs( node.children ) do visit( child ) end 347339 return detected return detected 350-local 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 362342local process_info_program = function ( tab )local process_info_program = function ( tab ) 363343 local pane_id = tab.active_pane and tab.active_pane.pane_id local pane_id = tab.active_pane and tab.active_pane.pane_id 364344 if not pane_id then return nil end if not pane_id then return nil end 369349 local ok_info, info = pcall( mux_pane.get_foreground_process_info, mux_pane ) 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 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 352+ return detect_from_process_info( info ) 377355local tab_title = function ( tab )local tab_title = function ( tab ) 378356 local id = tab.tab_id or tab.tab_index local id = tab.tab_id or tab.tab_index 379357 local explicit_title = apps.clean_title( tab.tab_title ) local explicit_title = apps.clean_title( tab.tab_title ) 380358 local pane_title = apps.clean_title( tab.active_pane.title ) 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 {} 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) 395- or (not weak_title and apps.is_root( from_title ) and from_title) 396- or (apps.is_root( from_title ) and from_title) 401- local cached = stable_tab_programs[id] 402- if not cached or (detected ~= 'nu' and detected ~= cached) then 404- stable_tab_programs[id] = cached 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 413375local tab_colors = function ( tab, hover )local tab_colors = function ( tab, hover ) 454416 local left_sep = wez.nerdfonts.ple_left_half_circle_thick or '\u{e0b4}' 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}' local right_sep = wez.nerdfonts.ple_right_half_circle_thick or '\u{e0b6}' 456418 local dot = tab.is_active and '●' or '○' local dot = tab.is_active and '●' or '○' 457- local budget = math.max( 1, max_width - 10 ) 419+ local chrome_width = 8 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 ) local text = wez.truncate_right( string.format( ' %s %d %s %s', dot, tab.tab_index + 1, icon, title ), budget ) 460423 local elements = { local elements = {