Last active
August 2, 2026 12:42
-
-
Save s-mage/f3b115239ce84f393b7adfb1eecc5c61 to your computer and use it in GitHub Desktop.
emulate foreman in wezterm. Not very successfully. TODO: try again when https://github.com/wezterm/wezterm/issues/1970 is solved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Helper function to parse Procfile lines | |
| local function parse_procfile(dir) | |
| local commands = {} | |
| local file_path = dir .. '/Procfile.dev' | |
| local f = io.open(file_path, 'r') | |
| if f then | |
| for line in f:lines() do | |
| if line ~= '' and not line:match('^%s*#') then | |
| local name, cmd = line:match('^%s*([%w%-_]+)%s*:%s*(.+)$') | |
| if name and cmd then | |
| table.insert(commands, { name = name, cmd = cmd }) | |
| end | |
| end | |
| end | |
| f:close() | |
| end | |
| return commands | |
| end | |
| -- Define layout logic as a global WezTerm Event Listener | |
| wezterm.on('run-foreman', function(window, pane) | |
| local cwd = pane:get_current_working_dir() | |
| if not cwd then return end | |
| local path = cwd.file_path | |
| wezterm.log_info("Triggered Foreman script in directory: " .. path) | |
| local services = parse_procfile(path) | |
| if #services == 0 then | |
| wezterm.log_error("No Procfile.dev found in " .. path) | |
| return | |
| end | |
| wezterm.log_info("Found " .. #services .. " commands to execute.") | |
| local current_pane = pane | |
| -- Track the primary master pane at the top | |
| local master_pane = pane | |
| local total_services = #services | |
| for i, service in ipairs(services) do | |
| local cmd_args = { 'sh', '-c', string.format([[printf "\033]2;%s\007"; %s]], service.name, service.cmd) } | |
| if i == 1 then | |
| -- First service runs in the original pane (use send_text safely here) | |
| master_pane:send_text(string.format([[printf "\033]2;%s\007"; %s]] .. "\n", service.name, service.cmd)) | |
| else | |
| -- Background services are split into 1-cell high rows at the bottom | |
| master_pane:split({ | |
| direction = 'Bottom', | |
| size = 0.04, -- Compresses background panes into a single line | |
| cwd = path, | |
| args = cmd_args, -- Isolated execution prevents bash 'command not found' errors | |
| }) | |
| end | |
| end | |
| end) | |
| config.keys = { | |
| -- ... | |
| { key = 'p', mods = 'CMD', action = wezterm.action.EmitEvent 'run-foreman', }, | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment