New Terminal for Windows
This post documents my configuration for an open source cross-platform terminal emulator "Wezterm"
# Reasons to use Wezterm
Unlike Linux, there are not many good terminal emulators on Windows. Windows Terminal seems to be the only viable option for many people. I have been using Windows Terminal since it is out as beta. It gets most of the job done and definitely looks better than the original terminal emulator comes with Windows almost forever ago.
However, it just lacks the flexibility in terms of configuration like many other windows programs. I can't do things like:
- Moving around using VIM keys
- Multi-window navigations
- Searching scroll-back history
- Emojis, rendering bold, italic, underline etc.
Wezterm (opens new window) is a GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez (opens new window). It is still in heavy development but it is already very usable.
The documentation is really good so I don't have to spend a lot of time trying to learn and tweak to fit my daily workflow.
# Configuration
The configuration is in Lua which is another plus for the terminal. It didn't take long for me to give it a very basic configuration.
You can basically write every configuration in a lua table and then return it in the ".wezterm.lua" file.
return {
-- your configuration goes here
}
First a few basic settings such as default shell, colors and fonts.
-- default shell
default_prog = {
"c:/Program Files/WindowsApps/Microsoft.PowerShell_7.1.3.0_x64__8wekyb3d8bbwe/pwsh.exe",
"-noLogo"
},
-- Appearance
default_cursor_style = "BlinkingBar",
font = wezterm.font("Hack"),
color_scheme = "tokyonight",
inactive_pane_hsb = {
saturation = 0.8,
brightness = 0.4,
},
Now, here comes my keybindings, which are all stored in the keys
table. Each keybinding and its action is stored in echo of the key
lua table.
Wezterm offers a cool way to select the terminal panes when you have multiple splits.
-- activate pane selection mode with the default alphabet (labels are "a", "s", "d", "f" and so on)
{key="8", mods="CTRL", action=act.PaneSelect},
-- activate pane selection mode with numeric labels
{key="9", mods="CTRL", action=act.PaneSelect{alphabet="1234567890"}},
-- show the pane selection mode, but have it swap the active and selected panes
{key="0", mods="CTRL", action=act.PaneSelect{mode="SwapWithActive"}},
For panes navigation and resizing, I use VIM keys.
-- window navigation
{ key = "h", mods="ALT",
action=act.ActivatePaneDirection("Left")},
{ key = "l", mods="ALT",
action=act.ActivatePaneDirection("Right")},
{ key = "k", mods="ALT",
action=act.ActivatePaneDirection("Up")},
{ key = "j", mods="ALT",
action=act.ActivatePaneDirection("Down")},
{ key = "H", mods = "ALT", action=act.AdjustPaneSize{"Left", 5} },
{ key = "J", mods = "ALT", action=act.AdjustPaneSize{"Down", 5} },
{ key = "K", mods = "ALT", action=act.AdjustPaneSize{"Up", 5} },
{ key = "L", mods = "ALT", action=act.AdjustPaneSize{"Right", 5} },
-- close tab
{ key = "q", mods="ALT", action=wezterm.action.CloseCurrentTab{confirm=true}},
-- toggle full screen
{ key = "F11", action=wezterm.action.ToggleFullScreen},
-- This will create a new split and run your default program inside it
{key="+", mods="ALT|SHIFT",
action=wezterm.action.SplitHorizontal{domain="CurrentPaneDomain"}},
{key="d", mods="ALT|SHIFT",
action=wezterm.action.SplitVertical{domain="CurrentPaneDomain"}},
-- Create a new tab in the same domain as the current pane.
{key="Enter", mods="ALT", action=act.SpawnTab("CurrentPaneDomain")},
The powershell prompt I'm using is defined below in my $PROFILE file:
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Set-Alias v nvim
Set-Alias py python
function prompt {
#Assign Windows Title Text
$host.ui.RawUI.WindowTitle = "Current Folder: $pwd"
#Configure current user, current folder and date outputs
$CmdPromptCurrentFolder = Split-Path -Path $pwd -Leaf
$CmdPromptUser = [Security.Principal.WindowsIdentity]::GetCurrent();
# Write-Host " $date " -ForegroundColor White
Write-Host "[" -NoNewline -ForegroundColor DarkRed
Write-Host "$($CmdPromptUser.Name.split("\")[1])" -NoNewline -ForegroundColor Yellow
Write-Host "@" -NoNewline -ForegroundColor DarkRed
Write-Host "$CmdPromptCurrentFolder" -NoNewline -ForegroundColor Magenta
Write-Host "]" -NoNewline -ForegroundColor DarkRed
return "$ "
} #end prompt function