A WezTerm utility to define and load tab/pane layouts from a configuration table.

May 15, 2026 ยท View on GitHub

-- ============================================================================= -- WezTerm Tab Loader Utility -- ============================================================================= -- DESCRIPTION: -- A helper script to define and load complex tab/pane layouts in WezTerm.

-- USAGE: -- 1. Copy this code into your wezterm.lua (or a separate file and require it). -- 2. Define your 'tabs' table (see example below). -- 3. Bind a key to trigger the 'apply_tabs' function.

-- EXAMPLE BINDING: -- { -- key = "t", mods = "LEADER", -- action = wezterm.action_callback(function(win, pane) -- pane:send_text "exit\n" -- Close current tab prompt -- apply_tabs(tabs, wezterm.mux.get_window(win:window_id())) -- end), -- } -- =============================================================================

local wezterm = require "wezterm"

-- [Example Definition] local tabs = { { tab_name = "Example", shell_command_before = "cd ~/tmp", panes = { { shell_command = "cd /var/log && ls -al | grep \.log" }, { shell_command = "echo second pane", split = "Right", size = 0.45 }, { shell_command = "echo third pane", split = "Bottom", size = 0.3 }, }, }, }

-- [Implementation] local function apply_tab(tab_def, mux_win) local system_shell = os.getenv "SHELL" or "bash" local first_pane = nil local last_pane = nil local cmd_before = tab_def.shell_command_before or ""

for i, p_conf in ipairs(tab_def.panes or {}) do local p_cmd = p_conf.shell_command or ":" local full_cmd = cmd_before ~= "" and (cmd_before .. " && " .. p_cmd) or p_cmd full_cmd = full_cmd .. "; exec " .. system_shell

if i == 1 then
  local tab = mux_win:spawn_tab { args = { system_shell, "-ic", full_cmd } }
  if tab_def.tab_name then
    tab:set_title(tab_def.tab_name)
  end
  first_pane = tab:active_pane()
  last_pane = first_pane
else
  last_pane = last_pane:split {
    direction = p_conf.split or "Bottom",
    size = p_conf.size,
    args = { system_shell, "-ic", full_cmd },
  }
end

end return first_pane end

function apply_tabs(tab_defs, mux_win) if not tab_defs or not mux_win then return end for _, tab_def in ipairs(tab_defs) do apply_tab(tab_def, mux_win) end end