Skip to content

Commit

Permalink
chore: update wezterm configs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xRichardH committed Dec 7, 2023
1 parent 8f69fa0 commit 4135a74
Showing 1 changed file with 125 additions and 98 deletions.
223 changes: 125 additions & 98 deletions config/wezterm/wezterm.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
local wezterm = require("wezterm")
local act = wezterm.action
local config = {}

-- ================== Helper functions <START> ==================
local helper = {}

helper.get_random_entry = function(tbl)
local keys = {}
for key, _ in ipairs(tbl) do
Expand All @@ -10,113 +14,136 @@ helper.get_random_entry = function(tbl)
return tbl[randomKey]
end

local config = {
automatically_reload_config = true,
}
local act = wezterm.action
local key_helper = {}

key_helper.multiple_actions = function(keys)
local actions = {}
for key in keys:gmatch(".") do
table.insert(actions, act.SendKey({ key = key }))
end
table.insert(actions, act.SendKey({ key = "\n" }))
return act.Multiple(actions)
end

key_helper.key_table = function(mods, key, action)
return {
mods = mods,
key = key,
action = action,
}
end

key_helper.cmd_key = function(key, action)
return key_helper.key_table("CMD", key, action)
end

key_helper.cmd_to_tmux_prefix = function(key, tmux_key)
return key_helper.cmd_key(
key,
act.Multiple({
act.SendKey({ mods = "CTRL", key = "b" }),
act.SendKey({ key = tmux_key }),
})
)
end
-- ================== Helper functions <END> ==================

-- In newer versions of wezterm, use the config_builder which will
-- help provide clearer error messages
if wezterm.config_builder then
config = wezterm.config_builder()
end

-- windows
config.color_scheme = "Catppuccin Mocha"
config.window_background_opacity = 0.90
-- config.window_background_opacity = 0.85
config.hide_tab_bar_if_only_one_tab = true
config.scrollback_lines = 36000
config.window_decorations = "RESIZE"

-- fonts
local fonts = {
"Monaspace Argon",
"Monaspace Krypton",
"Monaspace Neon",
"Monaspace Radon",
"Monaspace Xenon",
}
config.font = wezterm.font_with_fallback({
{
family = helper.get_random_entry(fonts),
weight = "Medium",
harfbuzz_features = { "ss01", "ss02", "ss03", "ss04", "ss05", "ss06", "ss07", "ss08", "calt", "dlig" },
},
{ family = "Comic Mono", weight = "Regular", stretch = "Normal", italic = false },
{ family = "Symbols Nerd Font Mono", scale = 0.85, italic = false },
})
config.font_size = 18.0
-- config.line_height = 1.2
-- config.cell_width = 1.1
config.use_cap_height_to_scale_fallback_fonts = true

-- keybindings
config.disable_default_key_bindings = false
config.leader = { key = "m", mods = "CMD" }
config.keys = {
--
-- vim
-- go to files
{
key = "p",
mods = "CMD",
action = act.SendString(":GoToFile\n"),
},
-- go to commands
{
key = "p",
mods = "CMD|SHIFT",
action = act.SendString(":GoToCommand\n"),
},
local custom_configs = {
automatically_reload_config = true,

--
-- tmux
-- tmux window selection
{ key = "1", mods = "CMD", action = act.SendString("\x021") },
{ key = "2", mods = "CMD", action = act.SendString("\x022") },
{ key = "3", mods = "CMD", action = act.SendString("\x023") },
{ key = "4", mods = "CMD", action = act.SendString("\x024") },
{ key = "5", mods = "CMD", action = act.SendString("\x025") },
{ key = "6", mods = "CMD", action = act.SendString("\x026") },
{ key = "7", mods = "CMD", action = act.SendString("\x027") },
{ key = "8", mods = "CMD", action = act.SendString("\x028") },
{ key = "9", mods = "CMD", action = act.SendString("\x029") },
-- Rename the current tmux window
{ key = ",", mods = "CMD", action = act.SendString("\x02,") },
-- clear tmux screen
{ key = "d", mods = "CMD", action = act.SendString("\x02\x0C") },
-- split tmux window vertically
{ key = "e", mods = "CMD", action = act.SendString("\x02|") },
-- split tmux window horizontally
{ key = "e", mods = "CMD|SHIFT", action = act.SendString("\x02-") },
-- start tmux search mode
{ key = "f", mods = "CMD|SHIFT", action = act.SendString("\x02\x5b\x2f") },
-- start file search mod
{ key = "f", mods = "CMD", action = act.SendString("v\n") },

-- open git manager 'jesseduffield/lazygit'
{ key = "g", mods = "CMD", action = act.SendString("\x02g") },
-- use (cmd+j) to open the session manager popup (t)
{
key = "j",
mods = "CMD",
action = act.SendString("\x02\x54"),
},
-- switch to the last tmux session
{ key = "l", mods = "CMD", action = act.SendString("\x02L") },
-- open file manager 'gokcehan/lf'
{
key = "o",
mods = "CMD",
action = act.SendString("lf\n"),
-- windows
color_scheme = "Catppuccin Mocha",
window_background_opacity = 0.90,
window_decorations = "RESIZE",
window_close_confirmation = "NeverPrompt",
hide_tab_bar_if_only_one_tab = true,
scrollback_lines = 36000,
adjust_window_size_when_changing_font_size = false,
debug_key_events = false,
enable_tab_bar = false,

-- fonts
font = wezterm.font_with_fallback({
{
family = helper.get_random_entry({
"Monaspace Argon",
"Monaspace Krypton",
"Monaspace Neon",
"Monaspace Radon",
"Monaspace Xenon",
}),
weight = "Medium",
harfbuzz_features = { "ss01", "ss02", "ss03", "ss04", "ss05", "ss06", "ss07", "ss08", "calt", "dlig" },
},
{ family = "Comic Mono", weight = "Regular", stretch = "Normal", italic = false },
{ family = "Symbols Nerd Font Mono", scale = 0.85, italic = false },
}),
font_size = 18.0,
use_cap_height_to_scale_fallback_fonts = true,
-- line_height = 1.2
-- cell_width = 1.1

-- keybindings
disable_default_key_bindings = false,
leader = { key = "m", mods = "CMD" },
keys = {
--
-- vim
key_helper.cmd_key("[", act.SendKey({ mods = "CTRL", key = "o" })),
key_helper.cmd_key("]", act.SendKey({ mods = "CTRL", key = "i" })),
-- go to files
key_helper.cmd_key("p", key_helper.multiple_actions(":GoToFile")),
-- go to commands
key_helper.cmd_key("P", key_helper.multiple_actions(":GoToCommand")),
-- quit vim
key_helper.cmd_key("q", key_helper.multiple_actions(":qa!")),

--
-- tmux
-- tmux window selection
key_helper.cmd_to_tmux_prefix("1", "1"),
key_helper.cmd_to_tmux_prefix("2", "2"),
key_helper.cmd_to_tmux_prefix("3", "3"),
key_helper.cmd_to_tmux_prefix("4", "4"),
key_helper.cmd_to_tmux_prefix("5", "5"),
key_helper.cmd_to_tmux_prefix("6", "6"),
key_helper.cmd_to_tmux_prefix("7", "7"),
key_helper.cmd_to_tmux_prefix("8", "8"),
key_helper.cmd_to_tmux_prefix("9", "9"),

-- Rename the current tmux window
key_helper.cmd_to_tmux_prefix(",", ","),
-- clear tmux screen
key_helper.cmd_to_tmux_prefix("d", "C"),
-- split tmux window vertically
key_helper.cmd_to_tmux_prefix("e", "|"),
-- split tmux window horizontally
key_helper.cmd_to_tmux_prefix("E", "-"),
-- open git manager 'jesseduffield/lazygit'
key_helper.cmd_to_tmux_prefix("g", "g"),
-- use (cmd+j) to open the session manager popup (t)
key_helper.cmd_to_tmux_prefix("j", "T"),
-- switch to the last tmux session
key_helper.cmd_to_tmux_prefix("l", "L"),
-- open file manager 'gokcehan/lf'
key_helper.cmd_key("o", key_helper.multiple_actions("lf")),
-- create a new tmux window
key_helper.cmd_to_tmux_prefix("t", "c"),
-- open URL (cmd+u)
key_helper.cmd_to_tmux_prefix("u", "u"),
-- kill the current tmux pane
key_helper.cmd_to_tmux_prefix("w", "x"),
},
-- create a new tmux window
{ key = "t", mods = "CMD", action = act.SendString("\x02c") },
-- open URL (cmd+u)
{ key = "u", mods = "CMD", action = act.SendString("\x02u") },
-- kill the current tmux pane
{ key = "w", mods = "CMD", action = act.SendString("\x02x") },
}

for k, v in pairs(custom_configs) do
config[k] = v
end

return config

0 comments on commit 4135a74

Please sign in to comment.