Created
September 4, 2024 12:49
-
-
Save sandromello/c83f5bac134cd28acf400f5b4cdebaf5 to your computer and use it in GitHub Desktop.
wezterm config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- $HOME/.config/wezterm/projects.lua | |
local wezterm = require 'wezterm' | |
local module = {} | |
local function project_dirs() | |
return { | |
'~/work/personal/joi2', | |
'~/work/hoopdev/hoop', | |
'~/work/hoopdev/documentation', | |
-- ... keep going, list all your projects | |
-- (or don't if you value your time. we'll improve on this soon) | |
} | |
end | |
function module.choose_project() | |
local choices = {} | |
for _, value in ipairs(project_dirs()) do | |
table.insert(choices, { label = value }) | |
end | |
return wezterm.action.InputSelector { | |
title = "Projects", | |
choices = choices, | |
fuzzy = true, | |
action = wezterm.action_callback(function(child_window, child_pane, id, label) | |
-- "label" may be empty if nothing was selected. Don't bother doing anything | |
-- when that happens. | |
if not label then return end | |
-- The SwitchToWorkspace action will switch us to a workspace if it already exists, | |
-- otherwise it will create it for us. | |
child_window:perform_action(wezterm.action.SwitchToWorkspace { | |
-- We'll give our new workspace a nice name, like the last path segment | |
-- of the directory we're opening up. | |
name = label:match("([^/]+)$"), | |
-- Here's the meat. We'll spawn a new terminal with the current working | |
-- directory set to the directory that was picked. | |
spawn = { cwd = label }, | |
}, child_pane) | |
end), | |
} | |
end | |
return module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- $HOME/.config/wezterm/wezterm.lua | |
local wezterm = require 'wezterm' | |
local projects = require 'projects' | |
local act = wezterm.action | |
local config = {} | |
config.window_frame = { | |
-- Berkeley Mono for me again, though an idea could be to try a | |
-- serif font here instead of monospace for a nicer look? | |
font = wezterm.font({ family = 'Jetbrains Mono', weight = 'Bold' }), | |
font_size = 11, | |
} | |
local function segments_for_right_status(window) | |
return { | |
window:active_workspace(), | |
wezterm.strftime('%a %b %-d %H:%M'), | |
wezterm.hostname(), | |
} | |
end | |
config.mouse_bindings = { | |
-- Change the default click behavior so that it only selects | |
-- text and doesn't open hyperlinks | |
{ | |
event={Up={streak=1, button="Left"}}, | |
mods="NONE", | |
action=act.CompleteSelection("PrimarySelection"), | |
}, | |
-- and make CTRL-Click open hyperlinks | |
{ | |
event={Up={streak=1, button="Left"}}, | |
mods="CMD", | |
action=act.OpenLinkAtMouseCursor, | |
}, | |
-- Disable the 'Down' event of CTRL-Click to avoid weird program behaviors | |
{ | |
event = { Down = { streak = 1, button = 'Left' } }, | |
mods = 'CMD', | |
action = act.Nop, | |
} | |
} | |
wezterm.on('update-status', function(window, _) | |
local SOLID_LEFT_ARROW = utf8.char(0xe0b2) | |
local segments = segments_for_right_status(window) | |
local color_scheme = window:effective_config().resolved_palette | |
-- Note the use of wezterm.color.parse here, this returns | |
-- a Color object, which comes with functionality for lightening | |
-- or darkening the colour (amongst other things). | |
local bg = wezterm.color.parse(color_scheme.background) | |
local fg = color_scheme.foreground | |
-- Each powerline segment is going to be coloured progressively | |
-- darker/lighter depending on whether we're on a dark/light colour | |
-- scheme. Let's establish the "from" and "to" bounds of our gradient. | |
local gradient_to, gradient_from = bg | |
gradient_from = gradient_to:lighten(0.2) | |
-- Yes, WezTerm supports creating gradients, because why not?! Although | |
-- they'd usually be used for setting high fidelity gradients on your terminal's | |
-- background, we'll use them here to give us a sample of the powerline segment | |
-- colours we need. | |
local gradient = wezterm.color.gradient( | |
{ | |
orientation = 'Horizontal', | |
colors = { gradient_from, gradient_to }, | |
}, | |
#segments -- only gives us as many colours as we have segments. | |
) | |
-- We'll build up the elements to send to wezterm.format in this table. | |
local elements = {} | |
for i, seg in ipairs(segments) do | |
local is_first = i == 1 | |
if is_first then | |
table.insert(elements, { Background = { Color = 'none' } }) | |
end | |
table.insert(elements, { Foreground = { Color = gradient[i] } }) | |
table.insert(elements, { Text = SOLID_LEFT_ARROW }) | |
table.insert(elements, { Foreground = { Color = fg } }) | |
table.insert(elements, { Background = { Color = gradient[i] } }) | |
table.insert(elements, { Text = ' ' .. seg .. ' ' }) | |
end | |
window:set_right_status(wezterm.format(elements)) | |
end) | |
config.keys = { | |
-- Turn off the default CMD-m Hide action, allowing CMD-m to | |
-- be potentially recognized and handled by the tab | |
{ | |
key = 'd', | |
mods = 'CMD|SHIFT', | |
action = wezterm.action.SplitVertical { domain = 'CurrentPaneDomain' }, | |
}, | |
{ | |
key = 'Enter', | |
mods = 'CMD|SHIFT', | |
action = wezterm.action.TogglePaneZoomState, | |
}, | |
{ key = 'Enter', mods = 'CMD', action = act.ToggleFullScreen }, | |
{ key = 'DownArrow', mods = 'CMD|OPT', action = wezterm.action.ActivatePaneDirection('Down') }, | |
{ key = 'UpArrow', mods = 'CMD|OPT', action = wezterm.action.ActivatePaneDirection('Up') }, | |
{ key = 'k', mods = 'CMD', action = wezterm.action.ShowLauncherArgs { flags = 'FUZZY|WORKSPACES' } }, | |
{ | |
key = 'K', | |
mods = 'CMD', | |
action = act.PromptInputLine { | |
description = wezterm.format { | |
{ Attribute = { Intensity = 'Bold' } }, | |
{ Foreground = { AnsiColor = 'Fuchsia' } }, | |
{ Text = 'Enter name for new workspace' }, | |
}, | |
action = wezterm.action_callback(function(window, pane, line) | |
-- line will be `nil` if they hit escape without entering anything | |
-- An empty string if they just hit enter | |
-- Or the actual line of text they wrote | |
if line then | |
window:perform_action( | |
act.SwitchToWorkspace { | |
name = line, | |
}, | |
pane | |
) | |
end | |
end), | |
}, | |
} | |
-- { key = 'k', mods = 'CMD', action = projects.choose_project() }, | |
} | |
config.key_tables = {} | |
config.key_tables.search_mode = { | |
{ key = 'c', mods = 'CTRL', action = act.Multiple({ act.CopyMode("ClearPattern"), act.CopyMode('Close') }) }, | |
{ key = 'Escape', mods = 'NONE', action = act.Multiple({ act.CopyMode("ClearPattern"), act.CopyMode('Close') }) }, | |
{ key = 'Enter', mods = 'NONE', action = act.CopyMode 'PriorMatch' }, | |
{ key = 'n', mods = 'CTRL', action = act.CopyMode 'NextMatch' }, | |
{ key = 'p', mods = 'CTRL', action = act.CopyMode 'PriorMatch' }, | |
{ key = 'r', mods = 'CTRL', action = act.CopyMode 'CycleMatchType' }, | |
{ key = 'u', mods = 'CTRL', action = act.CopyMode 'ClearPattern' }, | |
{ key = 'PageUp', mods = 'NONE', action = act.CopyMode 'PriorMatchPage' }, | |
{ key = 'PageDown', mods = 'NONE', action = act.CopyMode 'NextMatchPage' }, | |
{ key = 'UpArrow', mods = 'NONE', action = act.CopyMode 'PriorMatch' }, | |
{ key = 'DownArrow', mods = 'NONE', action = act.CopyMode 'NextMatch' }, | |
} | |
-- config.color_scheme = 'Darcula (base16)' | |
--config.color_scheme = 'Dracula (Official)' | |
--config.color_scheme = 'Dracula (Gogh)' | |
config.color_scheme = 'Dracula+' | |
-- config.color_scheme = 'darkmoss (base16)' | |
-- config.color_scheme = 'Deafened (terminal.sexy)' | |
-- config.color_scheme = 'Dracula (base16)' | |
config.font = | |
wezterm.font('JetBrains Mono', { italic = false }) | |
config.window_background_opacity = 0.89 | |
config.hyperlink_rules = wezterm.default_hyperlink_rules() | |
config.initial_rows = 35 | |
config.initial_cols = 185 | |
return config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment