Skip to content

Instantly share code, notes, and snippets.

@dmilith
Last active September 16, 2023 21:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmilith/841de041c27f559dff774638a4ed2286 to your computer and use it in GitHub Desktop.
Save dmilith/841de041c27f559dff774638a4ed2286 to your computer and use it in GitHub Desktop.
Wezterm Nightly configuration dmilith
local wezterm = require 'wezterm';
local mux = wezterm.mux
local act = wezterm.action
local MY_EDITOR = "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
return {
default_cwd = "/Volumes/Projects",
set_environment_variables={
TERMINFO_DIRS='~/.terminfo/',
TERM='xterm-256color',
},
term = "xterm-256color",
skip_close_confirmation_for_processes_named = {
"bash", "sh", "zsh", "fish", "tmux"
},
pane_focus_follows_mouse = true,
native_macos_fullscreen_mode = false,
enable_scroll_bar = true,
send_composed_key_when_left_alt_is_pressed=true,
send_composed_key_when_right_alt_is_pressed=true,
unicode_version = 14,
font_size = 26.5, --26,
line_height = 1.05,
initial_cols = 295,
initial_rows = 49,
window_background_opacity = 0.89,
scrollback_lines = 1000000,
audible_bell = "SystemBeep",
custom_block_glyphs = true,
default_cursor_style = "BlinkingBlock",
cursor_blink_rate = 800,
bold_brightens_ansi_colors = true,
use_resize_increments = false,
tab_bar_at_bottom = false,
hide_tab_bar_if_only_one_tab = true,
use_fancy_tab_bar = false,
show_tab_index_in_tab_bar = true,
font = wezterm.font({
family="Iosevka",
harfbuzz_features={"calt=1", "clig=1", "liga=1"},
}),
color_scheme = "Abernathy",
color_schemes = {
["Abernathy"] = {
cursor_border = "#52ad70",
cursor_bg = "#00f200",
cursor_fg = "#0c0c0c",
selection_fg = "white",
selection_bg = "#1972a1",
ansi = {"#0c0c0c", "#c91b00", "#00c200", "#ffaa00", "#4069e9", "#c930c7", "#00c5c7", "#c7c7c7"},
brights = {"#676767", "#ff6d67", "#5ff967", "#fefb67", "#6871ff", "#ff76ff", "#5ffdff", "#fffefe"},
}
},
window_decorations = "RESIZE",
key_tables = {
copy_mode = {
{key="c", mods="CTRL", action=act.CopyMode("Close")},
{key="g", mods="CTRL", action=act.CopyMode("Close")},
{key="q", mods="NONE", action=act.CopyMode("Close")},
{key="Escape", mods="NONE", action=act.CopyMode("Close")},
{key="h", mods="NONE", action=act.CopyMode("MoveLeft")},
{key="j", mods="NONE", action=act.CopyMode("MoveDown")},
{key="k", mods="NONE", action=act.CopyMode("MoveUp")},
{key="l", mods="NONE", action=act.CopyMode("MoveRight")},
{key="LeftArrow", mods="NONE", action=act.CopyMode("MoveLeft")},
{key="DownArrow", mods="NONE", action=act.CopyMode("MoveDown")},
{key="UpArrow", mods="NONE", action=act.CopyMode("MoveUp")},
{key="RightArrow", mods="NONE", action=act.CopyMode("MoveRight")},
{key="RightArrow", mods="ALT", action=act.CopyMode("MoveForwardWord")},
{key="f", mods="ALT", action=act.CopyMode("MoveForwardWord")},
{key="Tab", mods="NONE", action=act.CopyMode("MoveForwardWord")},
{key="w", mods="NONE", action=act.CopyMode("MoveForwardWord")},
{key="LeftArrow", mods="ALT", action=act.CopyMode("MoveBackwardWord")},
{key="b", mods="ALT", action=act.CopyMode("MoveBackwardWord")},
{key="Tab", mods="SHIFT", action=act.CopyMode("MoveBackwardWord")},
{key="b", mods="NONE", action=act.CopyMode("MoveBackwardWord")},
{key="0", mods="NONE", action=act.CopyMode("MoveToStartOfLine")},
{key="Enter", mods="NONE", action=act.CopyMode("MoveToStartOfNextLine")},
{key="$", mods="NONE", action=act.CopyMode("MoveToEndOfLineContent")},
{key="$", mods="SHIFT", action=act.CopyMode("MoveToEndOfLineContent")},
{key="^", mods="NONE", action=act.CopyMode("MoveToStartOfLineContent")},
{key="^", mods="SHIFT", action=act.CopyMode("MoveToStartOfLineContent")},
{key="m", mods="ALT", action=act.CopyMode("MoveToStartOfLineContent")},
{key=" ", mods="NONE", action=act.CopyMode{SetSelectionMode="Cell"}},
{key="v", mods="NONE", action=act.CopyMode{SetSelectionMode="Cell"}},
{key="V", mods="NONE", action=act.CopyMode{SetSelectionMode="Line"}},
{key="V", mods="SHIFT", action=act.CopyMode{SetSelectionMode="Line"}},
{key="v", mods="CTRL", action=act.CopyMode{SetSelectionMode="Block"}},
{key="G", mods="NONE", action=act.CopyMode("MoveToScrollbackBottom")},
{key="G", mods="SHIFT", action=act.CopyMode("MoveToScrollbackBottom")},
{key="g", mods="NONE", action=act.CopyMode("MoveToScrollbackTop")},
{key="H", mods="NONE", action=act.CopyMode("MoveToViewportTop")},
{key="H", mods="SHIFT", action=act.CopyMode("MoveToViewportTop")},
{key="M", mods="NONE", action=act.CopyMode("MoveToViewportMiddle")},
{key="M", mods="SHIFT", action=act.CopyMode("MoveToViewportMiddle")},
{key="L", mods="NONE", action=act.CopyMode("MoveToViewportBottom")},
{key="L", mods="SHIFT", action=act.CopyMode("MoveToViewportBottom")},
{key="o", mods="NONE", action=act.CopyMode("MoveToSelectionOtherEnd")},
{key="O", mods="NONE", action=act.CopyMode("MoveToSelectionOtherEndHoriz")},
{key="O", mods="SHIFT", action=act.CopyMode("MoveToSelectionOtherEndHoriz")},
{key="PageUp", mods="NONE", action=act.CopyMode("PageUp")},
{key="PageDown", mods="NONE", action=act.CopyMode("PageDown")},
{key="b", mods="CTRL", action=act.CopyMode("PageUp")},
{key="f", mods="CTRL", action=act.CopyMode("PageDown")},
{key="y", mods="NONE", action=act.Multiple{
-- act.Copy,
act.CompleteSelection("Clipboard"),
act.ClearSelection,
act.CopyMode("Close"),
}},
},
},
keys = {
{key="Enter", mods="SUPER", action="ToggleFullScreen"},
{key="l", mods="SUPER", action="ShowDebugOverlay"},
{key="k", mods="SUPER", action=act.ClearScrollback("ScrollbackAndViewport")},
{key="x", mods="SUPER", action="ActivateCopyMode"},
{key="s", mods="SUPER", action=act.QuickSelect},
{key="d", mods="SUPER", action=act.SplitPane{
direction="Right", -- command={args={"top"}},
size={Percent=50},
}},
{key="d", mods="SUPER|SHIFT", action=act.SplitPane{
direction="Down",
size={Percent=50},
}},
{key="UpArrow", mods="SUPER", action=act.ScrollByLine(-1)},
{key="DownArrow", mods="SUPER", action=act.ScrollByLine(1)},
},
window_padding = {
left = "0.3cell",
right = "0.3cell",
top = "0.3cell",
bottom = "0.3cell",
},
-- format tab naming
wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_width)
if tab.is_active then
return {
{Background={Color="#002010"}},
{Text= " " .. tab.tab_index + 1 .. " "},
}
else
return {
{Background={Color="black"}},
{Text= " " .. tab.tab_index + 1 .. " "},
}
end
return tab.active_pane.title
end),
-- position window to the top
wezterm.on("window-config-reloaded", function(window, pane)
window:set_position(0, 0)
end),
-- handle battery info
wezterm.on("update-right-status", function(window, pane)
-- The powerline < symbol
local LEFT_ARROW = utf8.char(0xe0b3);
-- The filled in variant of the < symbol
local SOLID_LEFT_ARROW = utf8.char(0xe0b2)
-- local SOLID_RIGHT_ARROW = utf8.char(0xe0b0)
-- Each element holds the text for a cell in a "powerline" style << fade
local cells = {};
-- Figure out the cwd and host of the current pane.
-- This will pick up the hostname for the remote host if your
-- shell is using OSC 7 on the remote host.
-- local cwd_uri = pane:get_current_working_dir()
-- if cwd_uri then
-- cwd_uri = cwd_uri:sub(8);
-- local slash = cwd_uri:find("/")
-- local cwd = ""
-- local hostname = ""
-- if slash then
-- hostname = cwd_uri:sub(1, slash-1)
-- -- Remove the domain name portion of the hostname
-- local dot = hostname:find("[.]")
-- if dot then
-- hostname = hostname:sub(1, dot-1)
-- end
-- -- and extract the cwd from the uri
-- cwd = cwd_uri:sub(slash)
-- table.insert(cells, cwd);
-- table.insert(cells, hostname);
-- end
-- end
-- Color palette for the backgrounds of each cell
local colors = {
"#002010",
"#02300a",
"#0c5295",
"#063a82",
};
-- local colors = {
-- "#52307c",
-- "#3c1361",
-- "#7c5295",
-- "#663a82",
-- };
-- I like my date/time in this style: "Wed Mar 3 08:14"
local date = wezterm.strftime("%a, %-d %b %Y");
table.insert(cells, date);
-- table.insert(cells, {Text=SOLID_LEFT_ARROW})
-- An entry for each battery (typically 0 or 1 battery)
for _, b in ipairs(wezterm.battery_info()) do
table.insert(cells, string.format("%.0f%%", b.state_of_charge * 100))
end
-- Foreground color for the text across the fade
local text_fg = "#c0c0c0";
-- The elements to be formatted
local elements = {};
-- How many cells have been formatted
local num_cells = 0;
-- table.insert(cells, {Background={Color=colors[2]}})
-- table.insert(cells, {Text=SOLID_LEFT_ARROW})
-- Translate a cell into elements
function push(text, is_last)
local cell_no = num_cells + 1
table.insert(elements, {Foreground={Color=text_fg}})
table.insert(elements, {Background={Color=colors[cell_no]}})
table.insert(elements, {Text=" "..text.." "})
if not is_last then
table.insert(elements, {Foreground={Color=colors[cell_no+1]}})
table.insert(elements, {Text=SOLID_LEFT_ARROW})
else
table.insert(elements, {Text="🔋"})
end
num_cells = num_cells + 1
end
while #cells > 0 do
local cell = table.remove(cells, 1)
push(cell, #cells == 0)
end
window:set_right_status(wezterm.format(elements));
end);
-- wezterm.on("gui-startup", function()
-- -- Set a workspace for coding on a current project
-- -- Top pane is for the editor, bottom pane is for the build tool
-- local project_dir = "/Volumes/Projects/esmon"
-- local tab, build_pane, window = mux.spawn_window{
-- workspace="coding",
-- cwd=project_dir,
-- }
-- local editor_pane = build_pane:split{
-- direction="Top",
-- size=0.6,
-- cwd=project_dir
-- }
-- -- may as well kick off a build in that pane
-- build_pane:send_text("cargo build\n")
-- -- A workspace for interacting with a local machine that
-- -- runs some docker containners for home automation
-- local tab, pane, window = mux.spawn_window{
-- workspace="automation",
-- args={"ssh", "vault"},
-- }
-- -- We want to startup in the coding workspace
-- mux.set_active_workspace("coding")
-- end),
wezterm.on("open-uri", function(window, pane, uri)
local prefix = "src"
local start, match_end = uri:find(prefix)
if start == 1 then
wezterm.log_info("opening editor for: " .. uri)
local file_at_some_position = prefix .. uri:sub(match_end+1)
window:perform_action(wezterm.action.SpawnCommandInNewWindow{args = {MY_EDITOR, file_at_some_position}}, pane)
-- prevent the default action from opening in a browser
return false
end
local prefix = "http"
local start, match_end = uri:find(prefix)
if start == 1 then
local an_url = prefix .. uri:sub(match_end+1)
wezterm.log_info("opening: " .. an_url)
window:perform_action(wezterm.action.SpawnCommandInNewWindow{args = {"open", an_url}}, pane)
return false
end
-- otherwise, by not specifying a return value, we allow later
-- handlers and ultimately the default action to caused the
-- URI to be opened in the browser
end),
-- handle src/path.rs:123:45 with MY_EDITOR
hyperlink_rules = {
{
regex = [[\b(src.*rs):(\d+):(\d+)\b]],
format = "$0",
},
{
regex = [[\bhttps?://\S*\b]],
format = "$0",
},
-- {
-- regex = [[["]?([\w\d]{1}[-\w\d]+)(/){1}([-\w\d\.]+)["]?]],
-- format = "https://www.github.com/$1/$3",
-- }
-- -- Make task numbers clickable
-- -- The first matched regex group is captured in $1.
-- {
-- regex = [[\b[tT](\d+)\b]],
-- format = "https://example.com/tasks/?t=$1",
-- },
-- -- Make username/project paths clickable. This implies paths like the following are for GitHub.
-- -- ( "nvim-treesitter/nvim-treesitter" | wbthomason/packer.nvim | wez/wezterm | "wez/wezterm.git" )
-- -- As long as a full URL hyperlink regex exists above this it should not match a full URL to
-- -- GitHub or GitLab / BitBucket (i.e. https://gitlab.com/user/project.git is still a whole clickable URL)
-- {
-- regex = [[["]?([\w\d]{1}[-\w\d]+)(/){1}([-\w\d\.]+)["]?]],
-- format = "https://www.github.com/$1/$3",
-- }
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment