repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

refactor(wezterm): remove ai shell and simplify config

fc2a3baefa9af62c0a4fb1e845a99fa5f7fc1fcd

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (14)

+100 / −560 text lines

Diff layout

wezterm/bugabinga/ai_shell.lua

Deleted
deleted file mode 100644

+0 / −187 text lines

1local wezterm = require 'wezterm'
2local system_prompt = require 'bugabinga.ai_system_prompt'
3
4local M = {}
5
6local API_URL = 'https://api.z.ai/api/coding/paas/v4/chat/completions'
7local MODEL = 'glm-5-turbo'
8local MAX_SCROLLBACK_LINES = 300
9
10local ai_state = {}
12local function get_ai_state(window)
13 local id = window:window_id()
14 if not ai_state[id] then
15 ai_state[id] = {
16 status = 'idle',
17 }
18 end
19 return ai_state[id]
20end
22function M.trigger_ai_shell(window, pane, question)
23 local state = get_ai_state(window)
24 state.status = 'loading'
26 local scrollback = pane:get_lines_as_text(MAX_SCROLLBACK_LINES)
28 local api_key = os.getenv 'ZAI_WEZTERM_API_KEY' or ''
29 wezterm.log_info('ai_shell: ZAI_WEZTERM_API_KEY present: ' .. (api_key ~= '' and 'yes' or 'NO - check WezTerm env vars'))
31 local user_content = 'RECENT SCROLLBACK:\n' .. scrollback .. '\n\n---\n\nUSER QUESTION: ' .. question
33 local json_payload = wezterm.json_encode({
34 model = MODEL,
35 messages = {
36 { role = 'system', content = system_prompt.prompt },
37 { role = 'user', content = user_content },
38 },
39 thinking = { type = 'disabled' },
40 stream = false,
41 max_tokens = 4096,
42 temperature = 0.6,
43 })
45 wezterm.log_info('ai_shell: requesting z.ai API')
47 local success, stdout, stderr = wezterm.run_child_process({
48 'curl', '-s', '-X', 'POST', API_URL,
49 '-H', 'Content-Type: application/json',
50 '-H', 'Authorization: Bearer ' .. api_key,
51 '-d', json_payload,
52 })
54 if not success or stdout == '' then
55 wezterm.log_error('ai_shell: curl failed or empty response: ' .. stderr)
56 state.status = 'offline'
57 wezterm.time.call_after(2, function()
58 state.status = 'idle'
59 end)
60 return
61 end
63 local ok, response = pcall(function()
64 return wezterm.json_parse(stdout)
65 end)
67 if not ok or not response or not response.choices or not response.choices[1] or not response.choices[1].message then
68 wezterm.log_error('ai_shell: API error: ' .. tostring(stdout))
69 state.status = 'error'
70 state.status = 'error'
71 wezterm.time.call_after(2, function()
72 state.status = 'idle'
73 end)
74 return
75 end
77 local command = M.strip_markdown(response.choices[1].message.content)
78 command = command:match('^%s*(.-)%s*$')
79 wezterm.log_info('ai_shell: executing: ' .. command)
81 pane:send_text(command)
83 state.status = 'success'
84 wezterm.time.call_after(1.5, function()
85 state.status = 'idle'
86 end)
87end
89function M.strip_markdown(text)
90 local lines = {}
91 for line in text:gmatch('[^\r\n]+') do
92 table.insert(lines, line)
93 end
95 if #lines > 0 and (lines[1]:match('^```%w*$') or lines[1] == '```') then
96 table.remove(lines, 1)
97 end
99 if #lines > 0 and lines[#lines] == '```' then
100 table.remove(lines, #lines)
101 end
103 local filtered = {}
104 for _, line in ipairs(lines) do
105 if line ~= '```' then
106 table.insert(filtered, line)
107 end
108 end
110 return table.concat(filtered, '\n')
111end
113function M.get_status_icon(window)
114 local state = get_ai_state(window)
116 local icon, color, label
118 if state.status == 'loading' then
119 icon = wezterm.nerdfonts.md_robot_confused
120 color = 'Yellow'
121 label = 'loading...'
122 elseif state.status == 'success' then
123 icon = wezterm.nerdfonts.md_robot_excited
124 color = 'Green'
125 label = 'done'
126 elseif state.status == 'error' then
127 icon = wezterm.nerdfonts.md_robot_dead
128 color = 'Red'
129 label = 'error'
130 elseif state.status == 'offline' then
131 icon = wezterm.nerdfonts.md_robot_off
132 color = 'Gray'
133 label = 'offline'
134 else
135 icon = wezterm.nerdfonts.md_robot
136 color = nil
137 label = nil
138 end
140 return icon, color, label
141end
143function M.get_status(window)
144 local icon, color, label = M.get_status_icon(window)
145 local parts = {}
146 if icon then
147 if color then
148 table.insert(parts, { Foreground = { AnsiColor = color } })
149 end
150 table.insert(parts, { Text = icon })
151 end
152 if label then
153 if color then
154 table.insert(parts, { Foreground = { AnsiColor = color } })
155 end
156 table.insert(parts, { Text = ' ' .. label })
157 end
158 return wezterm.format(parts)
159end
161function M.trigger_prompt(window, pane)
162 window:perform_action(
163 wezterm.action.PromptInputLine({
164 description = wezterm.format({
165 { Attribute = { Intensity = 'Bold' } },
166 { Foreground = { AnsiColor = 'Fuchsia' } },
167 { Text = '󰚩 Ask AI for Nushell command' },
168 { Text = '\n' },
169 { Attribute = { Intensity = 'Normal' } },
170 { Foreground = { AnsiColor = 'Silver' } },
171 { Text = 'e.g. "list only directories"' },
172 }),
173 prompt = wezterm.format({
174 { Foreground = { AnsiColor = 'Green' } },
175 { Text = '> ' },
176 }),
177 action = wezterm.action_callback(function(win, p, line)
178 if line and line ~= '' then
179 M.trigger_ai_shell(win, p, line)
180 end
181 end),
182 }),
183 pane
184 )
185end
187return M

wezterm/bugabinga/ai_system_prompt.lua

Deleted
deleted file mode 100644

+0 / −182 text lines

1local M = {}
2
3--[[
4 NUSHELL SYSTEM PROMPT
5 =====================
6
7 This prompt instructs the AI to generate valid Nushell commands.
8 Update this when Nushell syntax changes significantly.
9
10 KEY CRAFTING PRINCIPLES:
11 -------------------------
12 1. Be explicit about Nushell version (0.110+)
13 2. List common Bash-to-Nushell equivalents
14 3. Emphasize: NO markdown, NO code fences, raw command only
15 4. Include examples of modern Nushell syntax (pipelines, $env, etc.)
16 5. Warn about common pitfalls (> is comparison, not redirection)
17
18 RESOURCES FOR UPDATING:
19 -----------------------
20 - https://www.nushell.sh/book/thinking_in_nu.html
21 - https://www.nushell.sh/book/coming_from_bash.html
22 - https://www.nushell.sh/book/cheat_sheet.html
23 - https://www.nushell.sh/book/quick_tour.html
24
25 TESTING UPDATES:
26 ----------------
27 After updating, test with queries like:
28 - "list files in current directory"
29 - "find all .lua files recursively"
30 - "show only directories in current folder"
31 - "get the 5 largest files in current directory"
32]]
34M.prompt = [===[You are a Nushell (0.110+) expert. Generate ONLY raw shell commands valid in modern Nushell 0.110+.
36KEY NUSHELL CONCEPTS:
37- Nushell is NOT Bash. > is comparison operator, not redirection
38- Use pipeline syntax: "output | filter | transform"
39- Every command returns structured data (tables, lists, records), not plain text
40- Variables are immutable by default: use `let` not `=`. Use `mut` for mutable state
41- Command substitution / subexpression: use `(cmd)` NOT `cmd` or `$(cmd)`
42- String interpolation: $"text ($variable)"
43- Environment variables: $env.VAR (not $VAR). Set with: $env.VAR = value
44- $nu contains runtime info: config-path, env-path, current-exe, is-interactive
45- $env.config contains Nushell configuration
46- $in is current pipeline input
47- $it is current row/element in closures like `where` and `each`
48- Redirection: use `| save file` not `> file`. Use `out>` or `o>` for stdout where appropriate
49- External commands: prefix with ^ to run system command explicitly
50- Lists: [item1 item2], access with .index (not [index])
51- Records: {key: value}, access with .key
52- Tables: [[col1 col2]; [1 2]] or [{x: 1}, {x: 2}]
53- Conditionals/filters: use `where column == value` or `where $it =~ pattern` instead of grep
54- File globbing: **/*.rs; use `ls **/*.rs` for metadata table or `glob **/*.rs` for paths
55- Date handling: `date now`, `| into datetime`
56- Error handling: try/catch blocks
58BASH -> NUSHELL EQUIVALENTS:
59- $VAR -> $env.VAR
60- export VAR=val -> $env.VAR = val
61- echo $PATH -> $env.PATH
62- echo $? -> $env.LAST_EXIT_CODE
63- $(cmd) -> (cmd)
64- cd -> cd
65- ls -la -> ls --long --all or ls -la
66- cat file -> open --raw file
67- grep pattern -> where $it =~ pattern
68- find . -name "*.rs" -> ls **/*.rs or glob **/*.rs
69- [ -f file ] -> $file | path exists
70- basename path -> $path | path parse | get stem
71- > file -> | save file
72- >> file -> | save --append file
73- >/dev/null -> | ignore
74- 2>&1 -> o+e>| (external commands only)
75- sed/awk -> str replace, parse, split, each, reduce, select, update
76- && / || -> prefer `;`, `try/catch`, `if`, or inspect $env.LAST_EXIT_CODE
78PIPELINE PATTERNS:
79- Filter rows: ls | where size > 1mb
80- Filter dirs: ls | where type == dir
81- Regex filter: ls | where name =~ "^nu"
82- Select columns: ls | select name size
83- Insert computed column: ls | insert big {|row| $row.size > 1mb }
84- Update column: ls | update name { path parse | get stem }
85- Iterate list: [1 2 3] | each {|x| $x * 2 }
86- Filter list: [1 2 3] | where $it > 2
87- Reduce list: [1 2 3] | reduce {|val acc| $acc + $val }
89REDIRECTION:
90- Write file: "hello" | save output.txt
91- Append file: "hello" | save --append output.txt
92- Discard output: command | ignore
93- Redirect stderr from external command: ^external_cmd e>| ignore
94- Redirect stdout+stderr from external command: ^external_cmd o+e>| ignore
95- Redirect stdout+stderr to file from external command: ^external_cmd o+e>| error.log
96- e>| and o+e>| work for external commands only, not internal Nushell commands
97- For internal command errors, use try/catch instead of stderr redirection
99VARIABLES:
100- Immutable: let x = 10
101- List: let items = [1 2 3]
102- Record: let cfg = {theme: dark}
103- Compile-time constant: const PI = 3.14159
104- Mutable: mut y = 0; $y = 5
105- Env path prepend: $env.PATH = ($env.PATH | prepend "/custom")
106- Do not assign immutable vars with `$x = ...` unless declared `mut`
108STRINGS:
109- Literal string: 'hello world'
110- Escaped string: "hello\nworld"
111- Interpolation: $"hello, ($name)!"
112- Raw/no escapes: $'raw string'#
113- Raw with quotes: r#'can have "quotes"'#
115DATA TYPES:
116- int: 42
117- float: 3.14
118- bool: true or false
119- nothing/null: null
120- list: [1 2 3]
121- record: {a: 1, b: 2}
122- table: [{x: 1}, {x: 2}]
123- filesize: 10mb, 1gb
124- duration: 5sec, 2min
125- inclusive range: 1..10
126- exclusive range: 1..<10
128FUNCTIONS AND ALIASES:
129- Custom command: def greet [name: string] { $"Hello, ($name)!" }
130- Typed args: def add [a: int, b: int] { $a + $b }
131- Rest args: def sum [...nums: int] { $nums | math sum }
132- Alias: alias name = cmd
134CONTROL FLOW:
135- If: if $cond { "yes" } else { "no" }
136- Match: match $val { 1 => "one", 2 => "two", _ => "other" }
137- For loop: for i in 1..10 { print $i }
138- While loop: while $condition { ... }
139- Try/catch: try { risky_operation } catch {|err| print $err.msg }
140- Error: error make "something failed"
141- Structured error: error make {msg: "failed", help: "try this"}
142- Catch error record commonly has msg, debug, json fields; no direct code field
144EXTERNAL COMMANDS:
145- Explicit external: ^ls -la
146- Explicit external echo: ^echo "hello"
147- Spread args: let args = ["-la" "*.nu"]; ^ls ...$args
148- Use ^ when command name may conflict with an internal Nushell command
150MODULES:
151- Define module: module utils { export def add [a: int, b: int] { $a + $b } }
152- Use exported command: use utils add; add 5 3
154FILES:
155- Glob current dir: ls *.nu
156- Recursive glob: ls **/*.rs
157- Open parsed structured data: open file.json
158- Open raw text: open --raw file.txt
159- Check path exists: "/tmp" | path exists
161RUNNING NUSHELL:
162- Run script file: nu script.nu
163- Run one-liner: nu -c 'ls | where size > 1mb'
165COMMON MISTAKES TO AVOID:
166- Do NOT use Bash `2>&1`; use `o+e>|` for external commands
167- Do NOT use `$err.code`; use `$err.msg` or inspect `$err.json`
168- Do NOT write `ls | e>| ignore`; internal commands do not support stderr redirection
169- Do NOT use `$variable` for env vars; use `$env.variable`
170- Do NOT use `$(cmd)`; use `(cmd)`
171- Do NOT forget `^` before external commands when ambiguity is possible
172- Do NOT pipe structured data expecting plain strings; select/get columns explicitly
173- Do NOT use deprecated `$config`; use `$env.config`
174- Do NOT assign to immutable vars; use `mut` or `$env.var`
175- Do NOT use `test -f file`; use `$file | path exists`
177IMPORTANT:
178- Output ONLY the raw command. No markdown, no code fences, no backticks, no explanation.
179- If multiple commands are needed, separate with semicolons or newlines.
180- Prefer structured Nushell-native commands over Bash-style text processing.]===]
182return M

wezterm/bugabinga/apps.lua

Modified

+0 / −22 text lines

4646 presenterm = true,
49local QUIET_UNSEEN = {
50 aerc = true,
51 claude = true,
52 cmus = true,
53 codex = true,
54 nvim = true,
55 opencode = true,
56 pi = true,
57 vim = true,
58 weechat = true,
59 yazi = true,
60 glow = true,
61 gitu = true,
62 presenterm = true,
63 youtui = true,
64}
6649local LABELS = {
6750 aerc = 'Aerc',
6851 claude = 'Claude',
230213 return program ~= nil and ROOT_APPS[program] == true
231214end
233function M.quiet_unseen(program)
234 program = M.normalize(program)
235 return program ~= nil and QUIET_UNSEEN[program] == true
236end
238216function M.label(program)
239217 program = M.normalize(program)
240218 if not program then return nil end

wezterm/bugabinga/battery.lua

Modified

+6 / −2 text lines

111111--- Gets the color representing a battery charge level.
112112---@param charge number The charge level (0.0 to 1.0).
113113---@return string hex_color The corresponding hex color.
114local function charge_icon_index(charge)
115 return math.max(1, math.min(math.ceil(charge * 10), 11))
116end
114118local function get_charge_color(charge)
115119 local red = { r = 255, g = 0, b = 0 }
116120 local yellow = { r = 255, g = 255, b = 0 }
168172 remaining = b.time_to_full
169173 icon = wezterm.format({
170174 { Foreground = { Color = get_charge_color(charge) } },
171 { Text = icons_charging[math.min(math.ceil(charge * 10), 11)] },
175 { Text = icons_charging[charge_icon_index(charge)] },
172176 })
173177 elseif condition == "Discharging" then -- Battery is discharging
174178 remaining = b.time_to_empty
175179 icon = wezterm.format({
176180 { Foreground = { Color = get_charge_color(charge) } },
177 { Text = icons_discharging[math.min(math.ceil(charge * 10), 11)] },
181 { Text = icons_discharging[charge_icon_index(charge)] },
178182 })
179183 elseif condition == "Unknown" and charge > 0.5 then -- Battery is (probably) at charge limit
180184 icon =

wezterm/bugabinga/exec_domains.lua

Modified

+2 / −0 text lines

3636end
3838return function(cfg)
39 if not wez.target_triple:find( 'linux', 1, true ) then return end
3941 cfg.exec_domains = {
4042 scoped_domain('scope:build', 'scope:build CPU 25% MEM max 256M', {
4143 'CPUQuota=25%',

wezterm/bugabinga/icons.lua

Modified

+0 / −11 text lines

66 ['bash'] = 'dev_bash',
77 ['zsh'] = 'dev_terminal',
88 ['fish'] = 'cod_terminal_cmd',
9 ['nu'] = 'cod_terminal_cmd',
109 ['sh'] = 'dev_terminal',
1211 -- other tools
1615 ['opencode'] = 'cod_terminal_cmd',
1817 -- editors / IDEs
19 ['nvim'] = 'dev_vim',
2018 ['neovide'] = 'dev_vim',
21 ['vim'] = 'dev_vim',
2219 ['vim.opti'] = 'dev_vim',
2320 ['helix'] = 'cod_edit',
2421 ['kak'] = 'cod_edit',
2522 ['kakoune'] = 'cod_edit',
26 ['nano'] = 'cod_file',
2824 -- web browsers
2925 ['firefox'] = 'dev_firefox',
5652 ['npm'] = 'dev_npm',
5753 ['pnpm'] = 'dev_pnpm',
5854 ['yarn'] = 'dev_yarn',
59 ['bun'] = 'dev_bun',
6156 -- languages / runtimes (ordered by popularity)
6257 ['node'] = 'dev_nodejs',
7267 ['pypy'] = 'dev_python',
7368 ['ruby'] = 'dev_ruby',
7469 ['ruby3'] = 'dev_ruby',
75 ['cargo'] = 'dev_rust',
76 ['rustc'] = 'dev_rust',
77 ['go'] = 'dev_go',
7870 ['go1.20'] = 'dev_go',
7971 ['go1.21'] = 'dev_go',
8072 ['go1.22'] = 'dev_go',
8981 ['keytool'] = 'dev_java',
9082 ['keytool.exe'] = 'dev_java',
9183 ['kotlin'] = 'dev_kotlin',
92 ['scala'] = 'dev_scala',
9384 ['gradle'] = 'dev_gradle',
9485 ['mvn'] = 'dev_java',
9586 ['mvnd'] = 'dev_java',
9889 ['php8.1'] = 'dev_php',
9990 ['php8.2'] = 'dev_php',
10091 ['php8.3'] = 'dev_php',
101 ['cabal'] = 'dev_haskell',
10292 ['ghc'] = 'dev_haskell',
103 ['stack'] = 'dev_haskell',
10493 ['elm'] = 'dev_elm',
10594 ['elixir'] = 'dev_elixir',
10695 ['mix'] = 'dev_elixir',

wezterm/bugabinga/key_binds.lua

Modified

+1 / −14 text lines

11local wez = require 'wezterm'
22local workspace_switcher = require 'bugabinga.workspace_switcher'
4local custom_action = function ( _ )
5 local id = 'custom-action-' .. tostring( wez.time.now() )
6 wez.on( id, _ )
7 return wez.action.EmitEvent( id )
8end
9
104local leader = { key = 'VoidSymbol', }
115if wez.target_triple:find 'windows' then
126 leader = { key = 'raw:255', }
137end
148local font_mode = ' Font mode (- + 0) ESC to exit'
159local pane_mode = ' Pane (hjklaqrvsrR=q HL)'
16local resize_pane_mode = 'ﭕ Resize Pane (hjkl HJKL)'
10local resize_pane_mode = ( wez.nerdfonts.md_resize or '↔' ) .. ' Resize Pane (hjkl HJKL)'
1812local key_tables = {
1913 [resize_pane_mode] = {
235229 mods = 'LEADER',
236230 action = wez.action.Search 'CurrentSelectionOrEmptyString',
237231 },
238 {
239 key = 'a',
240 mods = 'LEADER',
241 action = wez.action_callback(function(window, pane)
242 require('bugabinga.ai_shell').trigger_prompt(window, pane)
243 end),
244 },
245232 {
246233 key = ' ',
247234 mods = 'LEADER',

wezterm/bugabinga/launch.lua

Modified

+1 / −7 text lines

33return function ( cfg )
44 local launch_menu = {
5 {
6 label = 'OOM Test (scope:build)',
7 args = { 'nu', wez.home_dir .. '/Workspace/dotfiles/wezterm/scripts/leak-memory.nu', },
8 cwd = wez.home_dir .. '/Workspace/dotfiles/wezterm',
9 domain = { DomainName = 'scope:build', },
10 },
115 {
126 label = 'Anime (new)',
137 args = { 'ani-cli', },
6559 },
6660 {
6761 label = 'Host Info',
68 args = { 'nu', '-c', 'loop {clear; macchina --current-shell --interface wlp3s0; sleep 5sec}', },
62 args = { 'nu', '-c', 'loop {clear; macchina --current-shell; sleep 5sec}', },
6963 cwd = wez.home_dir,
7064 },
7165 {

wezterm/bugabinga/options.lua

Modified

+7 / −2 text lines

77 brightness = 0.69,
88 }
99 cfg.check_for_updates = false
10 cfg.enable_kitty_keyboard = not wez.target_triple:match 'win'
10 cfg.enable_kitty_keyboard = not wez.target_triple:find( 'windows', 1, true )
1111 cfg.audible_bell = 'Disabled'
1212 cfg.notification_handling = 'AlwaysShow'
13 cfg.warn_about_missing_glyphs = false
1314 cfg.visual_bell = {
1415 fade_in_duration_ms = 69,
1516 fade_out_duration_ms = 69,
1819 cfg.unzoom_on_switch_pane = true
1920 cfg.scrollback_lines = 100000
21 cfg.enable_wayland = os.getenv('WAYLAND_DISPLAY') ~= nil
22 -- Prefer native Wayland only when launched from a Linux Wayland session.
23 -- Leaves X11, macOS, and Windows alone.
24 if wez.target_triple:find( 'linux', 1, true ) and os.getenv 'WAYLAND_DISPLAY' then
25 cfg.enable_wayland = true
26 end
2227 cfg.font_size = 13
2328end

wezterm/bugabinga/presentation_mode.lua

Modified

+48 / −42 text lines

11-- stolen from https://github.com/xarvex/presentation.wez/blob/main/plugin/init.lua
3---@param t1 table
4---@param t2 table
5---@return table t
6local function deep_merge_table( t1, t2 )
7 for k, v in pairs( t2 ) do
8 if type( v ) == 'table' then
9 if type( t1[k] or false ) == 'table' then
10 deep_merge_table( t1[k] or {}, t2[k] or {} )
11 else
12 t1[k] = v
13 end
14 else
15 t1[k] = v
16 end
17 end
3local wez = require 'wezterm'
19 return t1
5local state_by_window = {}
6
7local function deep_copy( value )
8 if type( value ) ~= 'table' then return value end
9 local copy = {}
10 for key, item in pairs( value ) do
11 copy[key] = deep_copy( item )
12 end
13 return copy
2014end
22local presentation_active = false
23local presentation_prev_font_weight
24local presentation_prev_font_size
16local function ensure_font_override( config, overrides )
17 if not overrides.font then overrides.font = deep_copy( config.font or {} ) end
18 if not overrides.font.font then overrides.font.font = {} end
19 if not overrides.font.font[1] and config.font and config.font.font then
20 overrides.font.font[1] = deep_copy( config.font.font[1] )
21 end
22 return overrides.font.font[1]
23end
2625local function enable( win )
26 local id = win:window_id()
2727 local config = win:effective_config()
2828 local overrides = win:get_config_overrides() or {}
29 local font = ensure_font_override( config, overrides )
30 if not overrides.font then overrides.font = {} end
31 if not overrides.font.font then overrides.font.font = {} end
32 if not overrides.font.font[1] then overrides.font.font[1] = config.font.font[1] end
31 state_by_window[id] = {
32 active = true,
33 font_size = config.font_size,
34 font_weight = font and font.weight or nil,
35 }
34 presentation_prev_font_weight = config.font.font[1].weight
35 presentation_prev_font_size = config.font_size
37 overrides.font.font[1].weight = 'DemiBold'
38 overrides.font_size = presentation_prev_font_size * 2.0
37 if font then font.weight = 'DemiBold' end
38 overrides.font_size = config.font_size * 2.0
4040 win:toggle_fullscreen()
41 win:set_config_overrides( overrides )
42 wez.emit( 'bugabinga.presentation.activate', win )
43end
42 presentation_active = true
45local function disable( win )
46 local id = win:window_id()
47 local state = state_by_window[id]
48 if not state then return end
44 require 'wezterm'.emit( 'bugabinga.presentation.activate', win )
50 local config = win:effective_config()
51 local overrides = win:get_config_overrides() or {}
52 local font = ensure_font_override( config, overrides )
46 return overrides
54 if font then font.weight = state.font_weight end
55 overrides.font_size = state.font_size
57 win:toggle_fullscreen()
58 win:set_config_overrides( overrides )
59 state_by_window[id] = nil
60 wez.emit( 'bugabinga.presentation.deactivate', win )
4761end
4963local function toggle( win )
50 local overrides = win:get_config_overrides() or {}
51 if presentation_active then
52 overrides.font.font[1].weight = presentation_prev_font_weight
53 overrides.font_size = presentation_prev_font_size
55 win:toggle_fullscreen()
56 presentation_active = false
58 require 'wezterm'.emit( 'bugabinga.presentation.deactivate', win )
64 local state = state_by_window[win:window_id()]
65 if state and state.active then
66 disable( win )
5967 else
60 deep_merge_table( overrides, enable( win ) )
68 enable( win )
6169 end
63 win:set_config_overrides( overrides )
6470end
6672return {

wezterm/bugabinga/status.lua

Modified

+7 / −30 text lines

99local apps = require 'bugabinga.apps'
1111local FALLBACK_TAB_PROGRAM = 'nu'
12local WORKSPACE_SUMMARY_TTL_SECONDS = 2.0
13local PALETTE_REFRESH_TTL_SECONDS = 2.0
15local workspace_summary_cache = { at = 0, value = nil }
16local stable_tab_programs = {}
1713local tab_activity_until = {}
18local last_palette_refresh = 0
20local now = function ()
21 -- update-status must never depend on optional WezTerm time APIs. os.clock()
22 -- is enough for small TTLs and avoids stale status bars from callback errors.
23 return os.clock()
15local wall_seconds = function ()
16 return os.time()
2417end
2619local use_palette_for_scheme = function ( scheme )
2821end
3023local use_palette_for_window = function ( window )
31 -- effective_config() crosses into WezTerm internals; do not poll it at 10Hz.
32 local current_time = now()
33 if current_time - last_palette_refresh < PALETTE_REFRESH_TTL_SECONDS then return end
34 last_palette_refresh = current_time
3624 local ok, config = pcall( function () return window:effective_config() end )
3725 if ok and config then use_palette_for_scheme( config.color_scheme ) end
3826end
171159end
173161local workspace_summaries = function ()
174 -- Workspace contents change slowly, but update-status runs often for spinners.
175 -- Cache the expensive mux-wide scan and keep animation work local to tabs.
176 local current_time = now()
177 if workspace_summary_cache.value and current_time - workspace_summary_cache.at < WORKSPACE_SUMMARY_TTL_SECONDS then
178 return workspace_summary_cache.value
179 end
181162 local ok, mux_windows = pcall( wez.mux.all_windows )
182163 if not ok then return {} end
213194 end
214195 end
216 workspace_summary_cache = { at = current_time, value = summaries }
217197 return summaries
218198end
380360end
382362local tab_title = function ( tab )
383 local id = tab.tab_id or tab.tab_index
384363 local explicit_title = apps.clean_title( tab.tab_title )
385364 local pane_title = apps.clean_title( tab.active_pane.title )
386365 local display_title = explicit_title or pane_title
390369 or process_info_program( tab )
391370 or root_or_nil( tab.active_pane.foreground_process_name )
392371 or title_program( display_title )
393 or stable_tab_programs[id]
394372 or FALLBACK_TAB_PROGRAM
396 if detected ~= FALLBACK_TAB_PROGRAM then stable_tab_programs[id] = detected end
398374 local detail = title_detail( display_title, detected, explicit_title ~= nil )
399375 return tab_label( detected, detail ), program_icon( detected ), detected
400376end
410386 local badge, color = user_state_badge( tab.active_pane.user_vars )
411387 if badge then return badge, color end
413 badge, color = progress_badge( tab.active_pane.progress )
389 local has_progress, progress = pcall( function () return tab.active_pane.progress end )
390 badge, color = progress_badge( has_progress and progress or 0 )
414391 if badge then return badge, color end
416393 local id = tab.tab_id or tab.tab_index
417394 badge, color = activity_badge( tab.active_pane.title )
418395 if badge then
419 tab_activity_until[id] = now() + 2.0
396 tab_activity_until[id] = wall_seconds() + 2.0
420397 return badge, color
421398 end
423400 for _, pane_info in ipairs( tab.panes or {} ) do
424401 if pane_info.has_unseen_output then
425 tab_activity_until[id] = now() + 2.0
402 tab_activity_until[id] = wall_seconds() + 2.0
426403 return busy_badge()
427404 end
428405 end
429 if tab_activity_until[id] and tab_activity_until[id] > now() then
406 if tab_activity_until[id] and tab_activity_until[id] > wall_seconds() then
430407 return busy_badge()
431408 end
432409 tab_activity_until[id] = nil

wezterm/bugabinga/theme.lua

Modified

+15 / −35 text lines

44-- wezterm.gui is not available to the mux server, so take care to
55-- do something reasonable when this config is evaluated by the mux
6local get_nugu_mode = function ()
7 local file = io.open( wez.home_dir .. '/.cache/nugu/mode', 'r' )
8 if not file then return nil end
9 local mode = file:read '*l'
10 file:close()
11 if mode == 'dark' or mode == 'light' then return mode end
12 return nil
13end
615local get_appearance = function ()
7 if wez.gui then
8 return wez.gui.get_appearance()
9 end
16 local mode = get_nugu_mode()
17 if mode == 'dark' then return 'Dark' end
18 if mode == 'light' then return 'Light' end
19 if wez.gui then return wez.gui.get_appearance() end
1020 return 'Dark'
1121end
1323local scheme_for_appearance = function ( appearance )
14 if appearance:find( 'Dark', 1, true ) then
15 return 'nugu-dark'
16 else
17 return 'nugu-light'
18 end
24 if appearance:find( 'Dark', 1, true ) then return 'nugu-dark' end
25 return 'nugu-light'
1926end
2128return function ( cfg )
2835 -- Apply nugu window frame styling
2936 nugu.apply_window_frame( cfg, current_scheme )
33 cfg.font = wez.font_with_fallback { 'JetBrains Mono', }
34 cfg.font_rules = {
35 -- the goal is to make comments in neovim look beautiful
36 -- because comments are the true GOAT of code
37 {
38 italic = true,
39 intensity = 'Bold',
40 font = wez.font_with_fallback { {
41 family = 'JetBrains Mono',
42 weight = 'Bold',
43 style = 'Italic',
44 }, },
45 },
46 -- this gives string values in neovim a special touch
47 {
48 italic = true,
49 intensity = 'Normal',
50 font = wez.font_with_fallback { {
51 family = 'JetBrains Mono',
52 style = 'Italic',
53 }, },
54 },
56 }
5737end

wezterm/bugabinga/window.lua

Modified

+1 / −10 text lines

33return function ( cfg )
44 cfg.window_background_opacity = 1.0
5 if wez.target_triple:find 'windows' then
6 cfg.window_decorations = 'RESIZE'
7 else
8 cfg.window_decorations = 'RESIZE|NONE'
9 end
5 cfg.window_decorations = 'RESIZE'
106 cfg.use_resize_increments = true
117 cfg.adjust_window_size_when_changing_font_size = false
13 cfg.window_content_alignment = {
14 horizontal = 'Center',
15 vertical = 'Center',
16 }
189 cfg.window_padding = {
1910 left = 0.5,
2011 right = 0.5,

wezterm/bugabinga/workspace_switcher.lua

Modified

+12 / −16 text lines

77local zoxide_path = 'zoxide'
9local is_windows = string.find( wezterm.target_triple, 'windows' ) ~= nil
119local function workspace_formatter( label )
1210 return wezterm.format {
1311 { Text = '󱂬 : ' .. label, },
1412 }
1513end
17local run_child_process = function ( cmd )
18 local process_args = { os.getenv 'SHELL', '-c', cmd, }
19 if is_windows then
20 process_args = { 'cmd', '/c', cmd, }
21 end
22 local success, stdout, stderr = wezterm.run_child_process( process_args )
15local run_child_process = function ( args )
16 local success, stdout, stderr = wezterm.run_child_process( args )
2418 if not success then
25 wezterm.log_error( "Child process '" .. cmd .. "' failed with stderr: '" .. stderr .. "'" )
19 wezterm.log_error( "Child process '" .. table.concat( args, ' ' ) .. "' failed with stderr: '" .. stderr .. "'" )
2620 end
27 return stdout
21 return stdout or ''
2822end
3024local function get_workspace_elements( choice_table )
5246end
5448local function get_zoxide_elements( choice_table, workspace_ids )
55 local stdout = run_child_process( zoxide_path .. ' query -l ' )
49 local stdout = run_child_process { zoxide_path, 'query', '-l' }
5751 for _, path in ipairs( wezterm.split_by_newlines( stdout ) ) do
5852 add_path_element( choice_table, workspace_ids, path )
6357local function get_workspace_dir_elements( choice_table, workspace_ids )
6458 local workspace_dir = wezterm.home_dir .. '/Workspace'
65 local stdout = run_child_process( 'find ' .. workspace_dir .. ' -mindepth 1 -maxdepth 1 -type d | sort' )
66 for _, path in ipairs( wezterm.split_by_newlines( stdout ) ) do
59 local stdout = run_child_process { 'find', workspace_dir, '-mindepth', '1', '-maxdepth', '1', '-type', 'd' }
60 local paths = wezterm.split_by_newlines( stdout )
61 table.sort( paths )
62 for _, path in ipairs( paths ) do
6763 add_path_element( choice_table, workspace_ids, path )
6864 end
6965 return choice_table
9187 pane
9288 )
9389 -- increment zoxide path score
94 run_child_process( zoxide_path .. ' add ' .. path )
90 run_child_process { zoxide_path, 'add', path }
9591end
9793local function workspace_chosen( window, pane, workspace )
107103 -- `mux.spawn_window()` and `wezterm cli spawn --new-window` create mux
108104 -- windows, which can appear in the workspace HUD without necessarily mapping
109105 -- a new OS/WM window. For the workflow-window use-case, force a fresh GUI.
110 local args = { 'wezterm', 'start', '--always-new-process', '--workspace', workspace }
106 local args = { os.getenv 'WEZTERM_EXECUTABLE' or 'wezterm', 'start', '--always-new-process', '--workspace', workspace }
111107 if cwd then
112108 table.insert( args, '--cwd' )
113109 table.insert( args, cwd )
126122local function zoxide_chosen_in_new_window( window, path, label_path )
127123 spawn_workspace_window( window, label_path, path )
128124 -- increment zoxide path score
129 run_child_process( zoxide_path .. ' add ' .. path )
125 run_child_process { zoxide_path, 'add', path }
130126end
132128local function workspace_chosen_in_new_window( window, workspace )