WezTerm Config Guide: Complete Lua Setup with Examples · Hey! It's Gilbert!<br>↓<br>Skip to main content<br>Hey! It’s Gilbert!
Posts
Notes
Projects
六‍ Presentations
️ Tags
️ RSS
Table of Contents<br>Table of Contents
Terminals, Shells, and Prompts -<br>This article is part of a series.Part 1:<br>Terminals, Shells, and Prompts: Complete Beginner's Guide<br>Part 2:<br>This Article<br>Part 3:<br>PowerShell Profile Setup Guide: Optimization & Starship Integration<br>Part 4:<br>Starship Transient Prompt: What It Is & How to Set It Up in PowerShell<br>This is the second post in this series. You can see the first post explaining<br>Terminals, Shells & Prompts. In<br>this post I’ll be covering my specific settings.<br>You can see the latest copy of my config files here:<br>HeyItsGilbert/dotfiles<br>My goals<br>These are my overall goals with my particular setup.<br>Configs that I can sync between computers of any OS.<br>Allow flexibility to add machine/environment specific options (e.g. work).<br>Allow ability to swap any component when I see the next new shiny thing.<br>WezTerm: Cross Platform & Flexible<br>WezTerm was written by Wez Furlong. He’s a<br>former Meta employee and created tools like Watchman and EdenFS. Hands down one<br>of the smartest and humblest engineers I’ve had the privilege of interacting<br>with. If you’re looking for a mentor, Wez offers mentoring at his<br>patreon.<br>WezTerm is written in Rust which is gaining popularity lately. Its configuration<br>is based in LUA which unlocks a ton of possibilities. It’s use of a single config<br>file helps me meet all three of my goals.<br>If you haven’t read the Quick Start for the config, I would recommend starting<br>there. WezTerm Configuration Quick Start<br>My WezTerm Config<br>You can see the latest copy of my config files here:<br>HeyItsGilbert/dotfiles<br>The WezTerm config is stored in .wezterm.lua which I put in my home directory.<br>It starts with some initial imports and variables.<br>-- The only required line is this one.<br>local wezterm = require 'wezterm'<br>local mux = wezterm.mux<br>local act = wezterm.action<br>-- Some empty tables for later use<br>local config = {}<br>local keys = {}<br>local mouse_bindings = {}<br>local launch_menu = {}This is where I try to import a module called “work”. The goal is to deploy the<br>work module through another internal process but still allow me to use the same<br>config. I’ll go over how I leverage that later.<br>local haswork,work = pcall(require,"work")LUA Logic: OS Checking<br>Now I start to check what OS I’m on. This is the power of LUA. It offers the<br>ability to add logic checks or executions.<br>if wezterm.target_triple == 'x86_64-pc-windows-msvc' then<br>--- Grab the ver info for later use.<br>local success, stdout, stderr = wezterm.run_child_process { 'cmd.exe', 'ver' }<br>local major, minor, build, rev = stdout:match("Version ([0-9]+)%.([0-9]+)%.([0-9]+)%.([0-9]+)")<br>local is_windows_11 = tonumber(build) >= 22000I check if I’m on Windows and then once I know I’m on Windows, I call out to<br>ver because it’s extremely fast. With some regex I can parse our the Major,<br>Minor, Build, and Revision number. Windows 11 is Major version 11 right? Nope.<br>It’s actually Build numbers higher then 22000. With that, I can make a local<br>bool variable called is_windows_11. I was planning on using this for some<br>themeing, but opted against it. Could be useful later…<br>This kind of OS-aware logic is what sold me on WezTerm — the config is actual code, not just a static settings file. But the terminal is only half the picture.<br>🎶 Here Comes Your Shell 🎶: PowerShell<br>On Windows the default shell is cmd. That’s gotta change… So I set<br>PowerShell Core as the default_prog. Then I insert two options into the<br>Launcher Menu,<br>one for Windows PowerShell and another for PowerShell Core.<br>--- Set Pwsh as the default on Windows<br>config.default_prog = { 'pwsh.exe', '-NoLogo' }
table.insert(launch_menu, {<br>label = 'PowerShell',<br>args = { 'powershell.exe', '-NoLogo' },<br>})<br>table.insert(launch_menu, {<br>label = 'Pwsh',<br>args = { 'pwsh.exe', '-NoLogo' },<br>})On non Windows I don’t set the default program, I just add PowerShell to the<br>Launcher Menu.<br>table.insert(launch_menu, {<br>label = 'Pwsh',<br>args = { '/usr/local/bin/pwsh', '-NoLogo' },<br>})In the next post I’ll be going over my PowerShell profile.<br>Conflicting Keyboard Shortcuts<br>I love PSReadLine! Once the ability to highlight or jump words was added, I was<br>never gonna look back. But here’s the first bump. That same shortcut (Ctrl +<br>Shift + Left/Right) is used by WezTerm for moving panes.<br>This portion of the config is long and I’ll spare you the scrolling. At a high<br>level, I created a new table called keys and added the standard set of<br>shortcuts. Then I commented out the conflicting shortcuts.<br>Selecting Shell Output<br>By integrating OSC 133 (see Escape Codes) into my PowerShell prompt I’m able to tell WezTerm where<br>my output is. This mouse binding allows me to triple click on my output to<br>select...