Beautiful command line - WezTerm

Sun, 6 Oct. 2024     Thomas Bendler     ~ 4 min to read

In the this post I will describe the installation and the theme of the terminal environment.

The Terminal

After quite a long time with iTerm2 as my primary terminal under macOS, I recently sought a slicker terminal variant. From a functional point of view, iTerm2 is still the best terminal as far as I know, however, the look isn’t that stylish anymore. The terminal that I had chosen, after some research, was WezTerm. WezTerm is a modern, stylish and fast terminal with extensive configuration options. It can be installed with Homebrew:

brew install --cask wezterm

The Configuration

Alacritty uses Tom’s Obvious Minimal Language or short, toml for its configuration. If you haven’t heard of toml, the configuration type is close to the ini configuration files, well known within the Windows world. The configuration files itself reside in the user’s home directory underneath the standard dot config directory. This needs to be created upfront:

mkdir -p ~/.config/wezterm
touch ~/.config/wezterm/wezterm.lua

The Customizing

One of the toughest decisions is the theme decision. A lot of themes are good, but I haven’t found one that is perfect. Some come close to perfect like the Cobalt2 theme, but it’s not fully supported for all applications I use. Finally, I ended up with Tokyo Night, which looks nice but is, compared to other nice-looking themes, out of the box widely supported within my application mix. To use the Tokyo Night theme, the file ~/.config/alacritty/themes/tokyo-night.toml with the following content needs to be created:

--- __      __      _
--- \ \    / /__ __| |_ ___ _ _ _ __
---  \ \/\/ / -_)_ /  _/ -_) '_| '  \
---   \_/\_/\___/__|\__\___|_| |_|_|_|
---
--- wezterm.lua - personal configuration

local wezterm = require("wezterm")
-- local mux = wezterm.mux

local config = {}
-- Use config builder object if possible
if wezterm.config_builder then
	config = wezterm.config_builder()
end

-- Set colorscheme
config.color_scheme = "Tokyo Night (Gogh)"

-- Font settings
config.font = wezterm.font("0xProto Nerd Font")
config.font_size = 16

-- Window setting/ appearance
config.window_decorations = "RESIZE"
config.enable_tab_bar = false
-- config.window_background_opacity = 0.85
-- config.macos_window_background_blur = 10

-- config.window_frame = {
-- 	font = wezterm.font({ family = "0xProto Nerd Font" }),
-- 	font_size = 20,
-- }

config.window_padding = {
	left = "1cell",
	right = "1cell",
	top = "0.0cell",
	bottom = "0.5cell",
}

config.initial_rows = 42
config.initial_cols = 124

config.enable_scroll_bar = true
config.scrollback_lines = 5000
config.default_workspace = "main"

-- Dim inactive panes
config.inactive_pane_hsb = {
	saturation = 0.24,
	brightness = 0.5,
}

-- Tab bar
-- config.enable_tab_bar = false
config.use_fancy_tab_bar = false
config.tab_bar_at_bottom = false
config.status_update_interval = 1000
wezterm.on("update-status", function(window, pane)
	local basename = function(s)
		return string.gsub(s, "(.*[/\\])(.*)", "%2")
	end

	-- Current working directory
	local cwd = pane:get_current_working_dir()
	if cwd then
		if type(cwd) == "userdata" then
			cwd = basename(cwd.file_path)
		else
			cwd = basename(cwd)
		end
	else
		cwd = ""
	end

	-- Current command
	local cmd = pane:get_foreground_process_name()
	cmd = cmd and basename(cmd) or ""

	-- Time
	local time = wezterm.strftime("%H:%M")

	-- Right status
	window:set_right_status(wezterm.format({
		{ Text = wezterm.nerdfonts.md_folder .. "  " .. cwd },
		{ Text = " | " },
		{ Foreground = { Color = "#e0af68" } },
		{ Text = wezterm.nerdfonts.fa_code .. "  " .. cmd },
		"ResetAttributes",
		{ Text = " | " },
		{ Text = wezterm.nerdfonts.md_clock .. "  " .. time },
		{ Text = "  " },
	}))
end)

-- Return the configuration to wezterm
return config

The result is a very nice-looking terminal:


WezTerm with eza and tldr
WezTerm with eza and tldr

Frankly spoken, it will look like this after the next blog post. Before, you need to tweak the Z-Shell.

Already quite solid, but not yet exactly what I’m aiming for. I would like to have some more information displayed within the terminal depending on what I’m doing. This will come with tmux, but before I start with tmux, I will first talk about some command line tool replacements.

Beautiful command line



Share on: