My wezterm configuration. Allows workspace configurations with environment variables for each new workspace pane.
wezterm is ready to go
3 files changed, +206 -0
+3-0.gitignore
| @@ -0,0 +1,3 @@ | ||
| 1 | + | |
| 2 | +/workspaces/* | |
| 3 | +!/workspaces/init.lua |
+97-0wezterm.lua
| @@ -0,0 +1,97 @@ | ||
| 1 | +local wezterm = require("wezterm") | |
| 2 | +local act = wezterm.action | |
| 3 | +local mux = wezterm.mux | |
| 4 | +local config = wezterm.config_builder() | |
| 5 | + | |
| 6 | +-- basic config | |
| 7 | +config.default_domain = "WSL:Ubuntu" | |
| 8 | + | |
| 9 | +-- window config | |
| 10 | +config.font = wezterm.font("Hack Nerd Font") | |
| 11 | +config.font_size = 11.0 | |
| 12 | +config.window_decorations = "RESIZE" | |
| 13 | +config.window_background_opacity = 0.85 | |
| 14 | +config.enable_scroll_bar = true | |
| 15 | +config.colors = { | |
| 16 | + scrollbar_thumb = "grey", | |
| 17 | +} | |
| 18 | +config.color_scheme = "Tokyo Night Storm" | |
| 19 | + | |
| 20 | +-- keymap | |
| 21 | +config.keys = { | |
| 22 | + -- vim-like pane movement | |
| 23 | + { key = "h", mods = "CTRL|SHIFT", action = act.ActivatePaneDirection("Left") }, | |
| 24 | + { key = "j", mods = "CTRL|SHIFT", action = act.ActivatePaneDirection("Down") }, | |
| 25 | + { key = "k", mods = "CTRL|SHIFT", action = act.ActivatePaneDirection("Up") }, | |
| 26 | + { key = "l", mods = "CTRL|SHIFT", action = act.ActivatePaneDirection("Right") }, | |
| 27 | + { key = "h", mods = "CTRL|SHIFT|ALT", action = act.AdjustPaneSize({ "Left", 3 }) }, | |
| 28 | + { key = "j", mods = "CTRL|SHIFT|ALT", action = act.AdjustPaneSize({ "Down", 3 }) }, | |
| 29 | + { key = "k", mods = "CTRL|SHIFT|ALT", action = act.AdjustPaneSize({ "Up", 3 }) }, | |
| 30 | + { key = "l", mods = "CTRL|SHIFT|ALT", action = act.AdjustPaneSize({ "Right", 3 }) }, | |
| 31 | + | |
| 32 | + -- debug | |
| 33 | + { key = "d", mods = "CTRL|SHIFT", action = act.ShowDebugOverlay }, | |
| 34 | + | |
| 35 | + -- quit all | |
| 36 | + { key = "q", mods = "CTRL|SHIFT", action = act.QuitApplication }, | |
| 37 | + | |
| 38 | + -- Show the launcher in fuzzy selection mode and have it list all workspaces | |
| 39 | + -- and allow activating one. | |
| 40 | + { | |
| 41 | + key = "9", | |
| 42 | + mods = "ALT", | |
| 43 | + action = act.ShowLauncherArgs({ | |
| 44 | + flags = "FUZZY|WORKSPACES", | |
| 45 | + }), | |
| 46 | + }, | |
| 47 | + { key = "n", mods = "ALT", action = act.SwitchWorkspaceRelative(1) }, | |
| 48 | + { key = "p", mods = "ALT", action = act.SwitchWorkspaceRelative(-1) }, | |
| 49 | + -- Prompt for a name to use for a new workspace and switch to it. | |
| 50 | + { | |
| 51 | + key = "w", | |
| 52 | + mods = "CTRL|SHIFT", | |
| 53 | + action = act.PromptInputLine({ | |
| 54 | + description = wezterm.format({ | |
| 55 | + { Attribute = { Intensity = "Bold" } }, | |
| 56 | + { Foreground = { AnsiColor = "Fuchsia" } }, | |
| 57 | + { Text = "Enter name for new workspace" }, | |
| 58 | + }), | |
| 59 | + action = wezterm.action_callback(function(window, pane, line) | |
| 60 | + -- line will be `nil` if they hit escape without entering anything | |
| 61 | + -- An empty string if they just hit enter | |
| 62 | + -- Or the actual line of text they wrote | |
| 63 | + if line then | |
| 64 | + window:perform_action( | |
| 65 | + act.SwitchToWorkspace({ | |
| 66 | + name = line, | |
| 67 | + }), | |
| 68 | + pane | |
| 69 | + ) | |
| 70 | + end | |
| 71 | + end), | |
| 72 | + }), | |
| 73 | + }, | |
| 74 | + | |
| 75 | + -- open lazygit | |
| 76 | + { | |
| 77 | + key = "g", | |
| 78 | + mods = "CTRL|SHIFT", | |
| 79 | + action = act.SpawnCommandInNewWindow({ args = { "lazygit" } }), | |
| 80 | + }, | |
| 81 | +} | |
| 82 | + | |
| 83 | +-- plugins | |
| 84 | +local tabline = wezterm.plugin.require("https://github.com/michaelbrusegard/tabline.wez") | |
| 85 | +tabline.setup() | |
| 86 | +tabline.apply_to_config(config) | |
| 87 | + | |
| 88 | +-- log success on reload | |
| 89 | +wezterm.on("window-config-reloaded", function(_, _) | |
| 90 | + wezterm.log_info("Successfully loaded config from .config") | |
| 91 | +end) | |
| 92 | + | |
| 93 | +-- load workspaces | |
| 94 | +local workspaces = require("workspaces") | |
| 95 | +workspaces.setup(config) | |
| 96 | + | |
| 97 | +return config |
+106-0workspaces/init.lua
| @@ -0,0 +1,106 @@ | ||
| 1 | +local wezterm = require("wezterm") | |
| 2 | +local mux = wezterm.mux | |
| 3 | +local act = wezterm.action | |
| 4 | +local manager = {} | |
| 5 | + | |
| 6 | +local M = {} | |
| 7 | + | |
| 8 | +-- Generates a string of environment variable exports for a given workspace. | |
| 9 | +-- | |
| 10 | +-- Parameters: | |
| 11 | +-- ws (string): The workspace identifier used to retrieve environment variables. | |
| 12 | +-- | |
| 13 | +-- Returns: | |
| 14 | +-- string: A concatenated string of export statements for the environment variables. | |
| 15 | +function M.env_text(ws) | |
| 16 | + local text = "" | |
| 17 | + if manager[ws].env then | |
| 18 | + for key, val in pairs(manager[ws].env) do | |
| 19 | + text = text .. "export " .. key .. "='" .. val .. "';" | |
| 20 | + end | |
| 21 | + end | |
| 22 | + return text | |
| 23 | +end | |
| 24 | + | |
| 25 | +function M.add_env(ws, pane) | |
| 26 | + pane:send_text(M.env_text(ws) .. "\n") | |
| 27 | +end | |
| 28 | + | |
| 29 | +function M.SplitWithEnv(direction) | |
| 30 | + return wezterm.action_callback(function(win, pane) | |
| 31 | + pane = pane:split({ direction = direction }) | |
| 32 | + local ws = win:get_workspace() | |
| 33 | + if manager[ws] and manager[ws].env then | |
| 34 | + pane.send_text(M.env_text(ws) .. "\n") | |
| 35 | + end | |
| 36 | + end) | |
| 37 | +end | |
| 38 | + | |
| 39 | +function M.add_keys(config) | |
| 40 | + table.insert(config.keys, { | |
| 41 | + key = '"', | |
| 42 | + mods = "CTRL|SHIFT", | |
| 43 | + action = M.SplitWithEnv("Bottom"), | |
| 44 | + }) | |
| 45 | + table.insert(config.keys, { | |
| 46 | + key = "%", | |
| 47 | + mods = "CTRL|SHIFT", | |
| 48 | + action = M.SplitWithEnv("Right"), | |
| 49 | + }) | |
| 50 | +end | |
| 51 | + | |
| 52 | +local function load_pane(ws, pane, pane_config) | |
| 53 | + M.add_env(ws, pane) | |
| 54 | + pane:send_text("clear\n") | |
| 55 | + if pane_config.init then | |
| 56 | + pane:send_text(table.concat(pane_config.init, ";") .. "\n") | |
| 57 | + end | |
| 58 | +end | |
| 59 | + | |
| 60 | +local function load_tab(ws, tab, tab_config) | |
| 61 | + load_pane(ws, tab:active_pane(), tab_config) | |
| 62 | + if tab_config.extra_panes then | |
| 63 | + for _, pane_config in ipairs(tab_config.extra_panes) do | |
| 64 | + local pane = tab:active_pane():split({ cwd = pane_config.cwd or tab_config.cwd or manager[ws].cwd }) | |
| 65 | + load_pane(ws, pane, pane_config) | |
| 66 | + end | |
| 67 | + end | |
| 68 | +end | |
| 69 | + | |
| 70 | +local function load_workspace(modname, ws) | |
| 71 | + local config = require(modname) | |
| 72 | + manager[ws] = config | |
| 73 | + local tab, _, window = mux.spawn_window({ | |
| 74 | + cwd = config.cwd, | |
| 75 | + workspace = ws, | |
| 76 | + }) | |
| 77 | + window:gui_window():maximize() | |
| 78 | + load_tab(ws, tab, config) | |
| 79 | + if config.extra_tabs then | |
| 80 | + for _, tab_config in ipairs(config.extra_tabs) do | |
| 81 | + tab, _, _ = window:spawn_tab({ cwd = tab_config.cwd or config.cwd }) | |
| 82 | + load_tab(ws, tab, tab_config) | |
| 83 | + end | |
| 84 | + end | |
| 85 | +end | |
| 86 | + | |
| 87 | +local function load_workspaces(config) | |
| 88 | + local wdir = wezterm.home_dir .. "/.config/wezterm/workspaces" | |
| 89 | + for _, v in ipairs(wezterm.read_dir(wdir)) do | |
| 90 | + -- setup modname agnostic of file system | |
| 91 | + local modname = v:match(".*%.config/wezterm/(.*)%.lua"):gsub("/", "."):gsub("\\", ".") | |
| 92 | + local wname = modname:match(".*%.(.*)") | |
| 93 | + if wname ~= "init" then | |
| 94 | + load_workspace(modname, wname) | |
| 95 | + end | |
| 96 | + end | |
| 97 | +end | |
| 98 | + | |
| 99 | +function M.setup(config) | |
| 100 | + M.add_keys(config) | |
| 101 | + wezterm.on("gui-startup", function() | |
| 102 | + load_workspaces(config) | |
| 103 | + end) | |
| 104 | +end | |
| 105 | + | |
| 106 | +return M |