dotfiles
bugabingas dorkfiles
owned by bugabinga
wezterm: add scoped build domain
f0d1c760c8a7b88b77082c1433b4896268b65831
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (7)
wezterm/bugabinga/exec_domains.lua
Addednew file mode 100644 1 +local wez
= require 'wezterm' 3 +local function append_all(dst, src)
4 + for _, value
in ipairs(src)
do 5 + table.
insert(dst, value)
9 +local function scoped_domain(name, label, properties)
10 + return wez.exec_domain(name,
function(cmd)
11 + local args
= cmd.args
or {
'nu',
'--login' }
12 + local env
= cmd.set_environment_variables
or {}
13 + env.WEZTERM_EXEC_DOMAIN
= name
14 + cmd.set_environment_variables
= env
15 + local unit
= 'wezterm-' .. name:gsub(
'[^%w_.-]',
'-')
.. '-' .. tostring(env.WEZTERM_PANE
or os.
time())
24 + '--description=WezTerm ' .. name,
27 + for _, property
in ipairs(properties)
do 28 + table.
insert(wrapped,
'-p')
29 + table.
insert(wrapped, property)
32 + append_all(wrapped, args)
39 + cfg.exec_domains
= {
40 + scoped_domain(
'scope:build',
'scope:build CPU 25% MEM max 256M', {
wezterm/bugabinga/key_binds.lua
Modified147 147 action
= wez.action.SpawnTab
'CurrentPaneDomain',
152 + action = wez.action.SpawnCommandInNewTab {
domain = {
DomainName =
'scope:build', }, },
156 + mods =
'LEADER|SHIFT',
157 + action = wez.action.SpawnCommandInNewTab {
domain =
'DefaultDomain', },
151 161 action = wez.action.ScrollByLine(
-1 ),
wezterm/bugabinga/launch.lua
Modified 2 2 local wez
= require 'wezterm' 4 4 return function ( cfg )
7 + label =
'OOM Test (scope:build)',
8 + args = {
'nu', wez.home_dir
.. '/Workspace/dotfiles/wezterm/scripts/leak-memory.nu', },
9 + cwd = wez.home_dir
.. '/Workspace/dotfiles/wezterm',
10 + domain = {
DomainName =
'scope:build', },
7 13 label =
'Anime (new)',
8 14 args = {
'ani-cli', },
wezterm/bugabinga/status.lua
Modified 242 +local domain_hud = function ( domain )
243 + if not domain
or domain
== 'local' or domain
== 'Local' then return {}
end 245 + local color
= palette.ui.important_local
246 + if domain:find(
'^scope:',
1,
false )
then color
= palette.warning
end 249 + {
Foreground = {
Color = color } },
250 + {
Attribute = {
Intensity =
'Bold' } },
251 + {
Text =
'@' .. domain
.. ' ' },
252 + {
Attribute = {
Intensity =
'Normal' } },
242 256 local tab_title = function ( tab )
243 257 if tab.tab_title
and #tab.tab_title
> 0 then 244 258 local explicit_program
= detect_program_from_title( tab.tab_title )
506 520 table.
insert( status, zoomed_state )
509 - if pane_domain
and pane_domain
~= 'local' and pane_domain
~= 'Local' then 510 - table.
insert( status,
'@' .. pane_domain )
513 523 local status_parts
= {}
514 524 for _, value
in ipairs( status )
do 515 525 if value
and value
~= '' then table.
insert( status_parts, value )
end 552 562 for _, element
in ipairs( workspace_hud( current_workspace ) )
do 553 563 table.
insert( left_elements, element )
565 + for _, element
in ipairs( domain_hud( pane_domain ) )
do 566 + table.
insert( left_elements, element )
557 570 window:set_left_status( wez.format( left_elements ) )
wezterm/scripts/leak-memory.nu
Addednew file mode 100755 4 + open --raw /proc/self/cgroup
6 + | parse --regex
'^(?P<id>[^:]*):(?P<controllers>[^:]*):(?P<path>.*)$' 9 + | str trim --left --char
'/' 10 + | $
'/sys/fs/cgroup/($in)' 13 +def read-cgroup-file [cg: string, name: string] {
14 + let path = (
$cg | path join
$name)
15 + try { open --raw
$path | str trim } catch { $
'<missing: ($name)>' }
19 + let cg = (cgroup-path)
20 + let sensitive_env_names = (
22 + | transpose name value
23 + |
where name =~
'(?i)(KEY|TOKEN|SECRET|PASSWORD)' 31 + shell: (
$env.SHELL? | default
'')
32 + wezterm_pane: (
$env.WEZTERM_PANE? | default
'')
33 + wezterm_exec_domain: (
$env.WEZTERM_EXEC_DOMAIN? | default
'')
35 + memory_current: (read-cgroup-file
$cg memory.current)
36 + memory_high: (read-cgroup-file
$cg memory.high)
37 + memory_max: (read-cgroup-file
$cg memory.max)
38 + memory_swap_max: (read-cgroup-file
$cg memory.swap.max)
39 + cpu_max: (read-cgroup-file
$cg cpu.max)
40 + env_count: (
$env | transpose name value | length)
41 + sensitive_env_names:
$sensitive_env_names 45 +let chunk_mib = (
$env.LEAK_CHUNK_MIB? | default
'16' | into int)
46 +let sleep_ms = ((
$env.LEAK_SLEEP_MS? | default
'50' | into int) * 1ms)
47 +let force = ((
$env.LEAK_FORCE? | default
'0') ==
'1')
48 +let info = (scope-info)
49 +let memory_max =
$info.memory_max 50 +let limited =
if $memory_max ==
'max' {
53 + try { (
$memory_max | into int) <=
1073741824 } catch { false }
56 +print (
$info | table --expand)
58 +if (not
$limited) and (not
$force) {
60 + print
'REFUSING: memory.max is not <= 1GiB. You are not in the tiny scope.' 61 + print
'Open scope first: LEADER b, then run this script again.' 62 + print
'Override only if intentional: LEAK_FORCE=1 nu scripts/leak-memory.nu' 67 +print $
'leaking ($chunk_mib) MiB every ($sleep_ms); expect cgroup OOM kill inside scope:build' 71 +let chunk_size = (
$chunk_mib *
1024 *
1024)
74 + let chunk = (random binary
$chunk_size)
75 + $chunks = (
$chunks | append
$chunk)
76 + $allocated = (
$allocated +
$chunk_mib)
77 + print $
'allocated=($allocated) MiB' wezterm/scripts/scope-info.nu
Addednew file mode 100755 4 + open --raw /proc/self/cgroup
6 + | parse --regex
'^(?P<id>[^:]*):(?P<controllers>[^:]*):(?P<path>.*)$' 9 + | str trim --left --char
'/' 10 + | $
'/sys/fs/cgroup/($in)' 13 +def read-cgroup-file [cg: string, name: string] {
14 + let path = (
$cg | path join
$name)
15 + try { open --raw
$path | str trim } catch { $
'<missing: ($name)>' }
18 +let cg = (cgroup-path)
19 +let sensitive_env_names = (
21 + | transpose name value
22 + |
where name =~
'(?i)(KEY|TOKEN|SECRET|PASSWORD)' 30 + shell: (
$env.SHELL? | default
'')
31 + wezterm_pane: (
$env.WEZTERM_PANE? | default
'')
32 + wezterm_exec_domain: (
$env.WEZTERM_EXEC_DOMAIN? | default
'')
34 + memory_current: (read-cgroup-file
$cg memory.current)
35 + memory_high: (read-cgroup-file
$cg memory.high)
36 + memory_max: (read-cgroup-file
$cg memory.max)
37 + memory_swap_max: (read-cgroup-file
$cg memory.swap.max)
38 + cpu_max: (read-cgroup-file
$cg cpu.max)
39 + env_count: (
$env | transpose name value | length)
40 + sensitive_env_names:
$sensitive_env_names wezterm/wezterm.lua
Modified 9 9 require 'bugabinga.window' ( cfg )
10 10 require 'bugabinga.status' ( cfg )
11 11 require 'bugabinga.launch' ( cfg )
12 +require 'bugabinga.exec_domains' ( cfg )
12 13 require 'bugabinga.hosts' ( cfg )