dotfiles/wezterm/wezterm.lua

263 lines
7 KiB
Lua
Raw Permalink Normal View History

2024-09-14 15:19:32 -04:00
-- Ctrl+Shift+R to force config reload
-- Ctrl+Shift+L to enter WezTerm REPL/Console
-- Ctrl+Shift+P to bring up WezTerm command palette
-- wezterm.log_info("debug")
local wezterm = require("wezterm")
local config = wezterm.config_builder()
config.initial_cols = 150
config.initial_rows = 48
config.scrollback_lines = 10000
2024-09-14 15:19:32 -04:00
config.hide_tab_bar_if_only_one_tab = true
config.tab_bar_at_bottom = true
config.use_fancy_tab_bar = false
2024-09-17 22:32:03 -04:00
config.show_new_tab_button_in_tab_bar = true
config.tab_max_width = 32
2024-09-14 15:19:32 -04:00
config.enable_scroll_bar = true
config.window_background_opacity = 0.8
config.window_padding = {
left = 0,
right = 0,
top = 0,
bottom = 0,
}
config.use_resize_increments = true
config.colors = {
foreground = "#ffffff",
background = "#000000",
cursor_fg = "#000000",
cursor_bg = "#ffffff",
cursor_border = "#ffffff",
ansi = {
"#171421", -- black
"#c01c28", -- red
"#26a269", -- green
"#a2734c", -- yellow
"#12488b", -- blue
"#a347ba", -- magenta
"#2aa1b3", -- cyan
"#d0cfcc", -- white
},
brights = {
"#5e5c64", -- black
"#f66151", -- red
"#33d17a", -- green
"#e9ad0c", -- yellow
"#2a7bde", -- blue
"#c061cb", -- magenta
"#33c7de", -- cyan
"#ffffff", -- white
},
2024-09-17 22:32:03 -04:00
tab_bar = {
active_tab = {
fg_color = "#33e7de",
bg_color = "#000000",
},
},
scrollbar_thumb = "#888888",
2024-09-14 15:19:32 -04:00
}
-- config.color_scheme = "Gnometerm (terminal.sexy)"
config.font = wezterm.font({
family = "Cascadia Mono",
harfbuzz_features = { "calt=0", "clig=0", "liga=0" },
})
config.font_size = 12
config.line_height = 1.0
config.freetype_load_target = "Light"
config.keys = {
{
key = "V",
mods = "CTRL|SHIFT|ALT",
action = wezterm.action.SplitVertical({ domain = "CurrentPaneDomain" }),
},
{
key = "H",
mods = "CTRL|SHIFT|ALT",
action = wezterm.action.SplitHorizontal({ domain = "CurrentPaneDomain" }),
},
{
key = "Q",
mods = "CTRL|SHIFT|ALT",
action = wezterm.action.CloseCurrentPane({ confirm = true }),
},
{
key = "F",
mods = "CTRL|SHIFT",
action = wezterm.action.Search({ CaseInSensitiveString = "" }),
},
}
2024-09-14 15:19:32 -04:00
--------------------------------------------------------------------------------
-- borrowed from: https://github.com/protiumx/.dotfiles/blob/main/stow/wezterm/.config/wezterm/wezterm.lua
-- wezterm.nerdfonts reference: https://wezfurlong.org/wezterm/config/lua/wezterm/nerdfonts.html
local process_icons = {
2024-09-14 21:45:17 -04:00
["bash"] = wezterm.nerdfonts.dev_terminal,
["btop"] = wezterm.nerdfonts.md_chart_bar,
2024-09-14 15:19:32 -04:00
["cargo"] = wezterm.nerdfonts.dev_rust,
["clj"] = wezterm.nerdfonts.dev_clojure,
["clojure"] = wezterm.nerdfonts.dev_clojure,
["curl"] = wezterm.nerdfonts.mdi_flattr,
["docker"] = wezterm.nerdfonts.linux_docker,
["docker-compose"] = wezterm.nerdfonts.linux_docker,
2025-01-19 22:02:56 -05:00
["emacs"] = wezterm.nerdfonts.custom_emacs,
["emacs-29"] = wezterm.nerdfonts.custom_emacs,
2024-09-14 15:19:32 -04:00
["git"] = wezterm.nerdfonts.dev_git,
["go"] = wezterm.nerdfonts.seti_go,
["htop"] = wezterm.nerdfonts.md_chart_bar,
["java"] = wezterm.nerdfonts.dev_java,
["kubectl"] = wezterm.nerdfonts.linux_docker,
["lein"] = wezterm.nerdfonts.dev_clojure,
2024-09-14 21:45:17 -04:00
["less"] = wezterm.nerdfonts.md_less_than,
2024-09-14 15:19:32 -04:00
["lua"] = wezterm.nerdfonts.seti_lua,
["make"] = wezterm.nerdfonts.seti_makefile,
2024-09-14 21:45:17 -04:00
["man"] = wezterm.nerdfonts.fa_book,
2024-09-14 15:19:32 -04:00
["nano"] = wezterm.nerdfonts.md_file_edit,
["node"] = wezterm.nerdfonts.mdi_hexagon,
["nvim"] = wezterm.nerdfonts.custom_neovim,
2024-09-14 21:45:17 -04:00
["perl"] = wezterm.nerdfonts.seti_perl,
2024-09-14 15:19:32 -04:00
["psql"] = "󱤢",
["python3"] = "",
["Python"] = "",
["ruby"] = wezterm.nerdfonts.cod_ruby,
2024-09-14 21:45:17 -04:00
["ssh"] = wezterm.nerdfonts.md_server,
["ssh-add"] = wezterm.nerdfonts.md_server,
2024-09-14 15:19:32 -04:00
["stern"] = wezterm.nerdfonts.linux_docker,
["sudo"] = wezterm.nerdfonts.fa_hashtag,
["vim"] = wezterm.nerdfonts.dev_vim,
["wget"] = wezterm.nerdfonts.mdi_arrow_down_box,
}
local process_use_suggested_title = {
["ssh"] = true,
}
local function get_suggested_tab_title(tab_info)
local title = tab_info.tab_title
if title and #title > 0 then
return title
end
return tab_info.active_pane.title
end
2024-09-14 15:19:32 -04:00
local function get_current_working_dir(tab)
local current_dir = tab.active_pane and tab.active_pane.current_working_dir or { file_path = "" }
local HOME_DIR = os.getenv("HOME")
return current_dir.file_path == HOME_DIR and "~" or string.gsub(current_dir.file_path, "(.*[/\\])(.*)", "%2")
end
local function get_process(tab)
if not tab.active_pane or tab.active_pane.foreground_process_name == "" then
return nil
end
local process_name = string.gsub(tab.active_pane.foreground_process_name, "(.*[/\\])(.*)", "%2")
if string.find(process_name, "kubectl") then
process_name = "kubectl"
end
if string.find(process_name, "python3") then
process_name = "python3"
end
2024-09-14 15:19:32 -04:00
return {
Icon = process_icons[process_name] or string.format("[%s]", process_name),
Process = process_name,
}
2024-09-14 15:19:32 -04:00
end
local SOLID_LEFT_ARROW = wezterm.nerdfonts.pl_right_hard_divider
local SOLID_RIGHT_ARROW = wezterm.nerdfonts.pl_left_hard_divider
wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_width)
local has_unseen_output = false
if not tab.is_active then
for _, pane in ipairs(tab.panes) do
if pane.has_unseen_output then
has_unseen_output = true
break
end
end
end
local cwd = wezterm.format({
{ Text = get_current_working_dir(tab) },
})
local process = get_process(tab)
local title
if process then
local icon = process.Icon or string.format("[%s]", process.Process)
if process_use_suggested_title[process.Process] then
title = string.format(" %s %s ", icon, get_suggested_tab_title(tab))
else
title = string.format(" %s (%s) ", icon, cwd)
end
else
title = string.format(" %s %s ", wezterm.nerdfonts.cod_terminal_bash, get_suggested_tab_title(tab))
end
2024-09-14 15:19:32 -04:00
if has_unseen_output then
return {
{ Foreground = { Color = "#ffffff" } },
{ Text = title },
}
end
return {
{ Text = title },
}
end)
--------------------------------------------------------------------------------
local act = wezterm.action
-- Some stuff below borrowed from comments here: https://github.com/wez/wezterm/issues/119
config.mouse_bindings = {
{
event = { Up = { streak = 1, button = "Left" } },
mods = "NONE",
action = act.CompleteSelection("PrimarySelection"),
},
-- ctrl+click to open urls, etc.
{
event = { Up = { streak = 1, button = "Left" } },
mods = "CTRL",
action = act.OpenLinkAtMouseCursor,
},
-- prevents weird behaviours from occuring given the about ctrl+click binding
{
event = { Down = { streak = 1, button = "Left" } },
mods = "CTRL",
action = act.Nop,
},
}
--------------------------------------------------------------------------------
-- copied from https://github.com/wez/wezterm/issues/4331
-- however it has some issues, seems to reset color theme to default?
-- wezterm.on("update-status", function(window, pane)
-- local overrides = window:get_config_overrides() or {}
-- if not overrides.colors then
-- overrides.colors = {}
-- end
-- if pane:is_alt_screen_active() then
-- overrides.colors.scrollbar_thumb = "transparent"
-- else
-- overrides.colors.scrollbar_thumb = nil
-- end
-- window:set_config_overrides(overrides)
-- end)
2024-09-14 15:19:32 -04:00
return config