Last active
September 24, 2024 05:31
-
-
Save danbruegge/5483431337a1329f0f1adc7be63fe44d to your computer and use it in GitHub Desktop.
Wezterm config for mac and windows
This file contains hidden or 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
local wezterm = require("wezterm") | |
local config = wezterm.config_builder() | |
local act = wezterm.action | |
local mux = wezterm.mux | |
local isWin = wezterm.target_triple == "x86_64-pc-windows-msvc" | |
local CMD = isWin and "CTRL" or "CMD" | |
config.default_workspace = "main" | |
config.font_size = isWin and 11 or 12 | |
config.line_height = isWin and 0.9 or 1.3 | |
config.cell_width = 0.9 | |
config.use_fancy_tab_bar = false | |
config.show_new_tab_button_in_tab_bar = false | |
config.status_update_interval = 2000 | |
config.scrollback_lines = 10000 | |
config.window_decorations = "RESIZE" | |
config.window_padding = { | |
left = "1cell", | |
right = "1cell", | |
top = "0.5cell", | |
bottom = "0.5cell", | |
} | |
local function get_appearance() | |
if wezterm.gui then | |
return wezterm.gui.get_appearance() | |
end | |
return "Dark" | |
end | |
local function scheme_for_appearance(appearance) | |
if appearance:find("Dark") then | |
return "Kong" | |
else | |
return "Gruvbox (Gogh)" | |
end | |
end | |
local themePath = "/workspace/kong/wezterm/" | |
config.color_scheme_dirs = | |
{ (isWin and "C:" or wezterm.home_dir) .. (isWin and themePath:gsub("/", "\\") or themePath) } | |
config.color_scheme = scheme_for_appearance(get_appearance()) | |
if isWin then | |
config.default_domain = "WSL:Ubuntu" | |
config.default_prog = { "C:\\Program Files\\Git\\bin\\bash.exe", "--login", "-i" } | |
end | |
wezterm.on("gui-startup", function() | |
local tab, pane, window = mux.spawn_window({}) | |
window:gui_window():maximize() | |
end) | |
local function cleanupString(s) | |
s = string.gsub(s, "^%s+", "") | |
s = string.gsub(s, "%s+$", "") | |
s = string.gsub(s, "[\n\r]+", "") | |
return s | |
end | |
local function get_current_git_branch(currentWorkingDir) | |
local _, stdout, stderr = wezterm.run_child_process({ | |
"git", | |
"--git-dir=" .. currentWorkingDir .. "/.git", | |
"--work-tree=" .. currentWorkingDir, | |
"rev-parse", | |
"--abbrev-ref", | |
"HEAD", | |
}) | |
local currentGitBranch = cleanupString(stdout) | |
if currentGitBranch == "" or stderr:find("fatal:") ~= nil then | |
return "No Git" | |
end | |
return currentGitBranch | |
end | |
local function get_has_git_uncommited_changes(currentWorkingDir) | |
local _, stdout, stderr = wezterm.run_child_process({ | |
"git", | |
"--git-dir=" .. currentWorkingDir .. "/.git", | |
"--work-tree=" .. currentWorkingDir, | |
"status", | |
"--porcelain", | |
}) | |
local result = cleanupString(stdout) | |
return not (result == "" or stderr:find("fatal:") ~= nil) | |
end | |
wezterm.on("update-status", function(window, pane) | |
local currentWorkingDir = pane:get_current_working_dir().file_path -- update path for windows and unix (maybe this is the reason, why the git status is not working) | |
local currentGitBranch = get_current_git_branch(currentWorkingDir) | |
local hasGitUncommitedChanges = get_has_git_uncommited_changes(currentWorkingDir) | |
local isLeaderActive = window:leader_is_active() | |
local activeWorkspaceIcon = isLeaderActive and wezterm.nerdfonts.md_layers_triple_outline | |
or wezterm.nerdfonts.md_layers_triple | |
local activeWorkspaceColor = isLeaderActive and "#e68455" or "#949598" | |
window:set_left_status(wezterm.format({ | |
{ Attribute = { Italic = true } }, | |
{ Foreground = { Color = "#949598" } }, | |
{ Text = " | " }, | |
{ Foreground = { Color = activeWorkspaceColor } }, | |
{ Text = activeWorkspaceIcon .. " " .. window:active_workspace() }, | |
{ Foreground = { Color = "#949598" } }, | |
{ Text = " | " }, | |
})) | |
window:set_right_status(wezterm.format({ | |
{ Foreground = { Color = "#949598" } }, | |
{ Text = " | " }, | |
{ Foreground = { Color = "#5faf5f" } }, | |
{ Text = wezterm.nerdfonts.custom_folder .. " " .. currentWorkingDir }, | |
{ Foreground = { Color = "#949598" } }, | |
{ Text = " | " }, | |
{ Foreground = { Color = hasGitUncommitedChanges and "#f55e67" or "#5faf5f" } }, | |
{ Text = wezterm.nerdfonts.dev_git_branch .. " " .. currentGitBranch }, | |
{ Foreground = { Color = "#949598" } }, | |
{ Text = " | " }, | |
})) | |
end) | |
config.inactive_pane_hsb = { | |
saturation = 0.5, | |
brightness = 0.5, | |
} | |
-- config.disable_default_key_bindings = true | |
config.leader = { key = "Home", timeout_milliseconds = 1000 } | |
config.keys = { | |
{ key = "Space", mods = "LEADER", action = act.ShowLauncher }, | |
-- Make Option-Left equivalent to Alt-b which many line editors interpret as backward-word | |
{ key = "LeftArrow", mods = "OPT", action = wezterm.action({ SendString = "\x1bb" }) }, | |
-- Make Option-Right equivalent to Alt-f; forward-word | |
{ key = "RightArrow", mods = "OPT", action = wezterm.action({ SendString = "\x1bf" }) }, | |
{ | |
key = "c", | |
mods = CMD, | |
action = wezterm.action_callback(function(window, pane) | |
local has_selection = window:get_selection_text_for_pane(pane) ~= "" | |
if has_selection then | |
window:perform_action(act({ CopyTo = "ClipboardAndPrimarySelection" }), pane) | |
window:perform_action("ClearSelection", pane) | |
else | |
window:perform_action(act({ SendKey = { key = "c", mods = CMD } }), pane) | |
end | |
end), | |
}, | |
{ key = "v", mods = CMD, action = act.PasteFrom("Clipboard") }, | |
{ key = "-", mods = "LEADER", action = act.SplitVertical({ domain = "CurrentPaneDomain" }) }, | |
{ key = "|", mods = "LEADER", action = act.SplitHorizontal({ domain = "CurrentPaneDomain" }) }, | |
{ key = "x", mods = "LEADER", action = act.CloseCurrentPane({ confirm = false }) }, | |
{ key = "j", mods = "LEADER", action = act.ActivatePaneDirection("Down") }, | |
{ key = "k", mods = "LEADER", action = act.ActivatePaneDirection("Up") }, | |
{ key = "h", mods = "LEADER", action = act.ActivatePaneDirection("Left") }, | |
{ key = "l", mods = "LEADER", action = act.ActivatePaneDirection("Right") }, | |
{ key = "t", mods = "LEADER", action = act.ShowTabNavigator }, | |
{ key = "t", mods = CMD, action = act.SpawnTab("CurrentPaneDomain") }, | |
{ key = "t", mods = CMD .. "|SHIFT", action = act.SpawnTab({ DomainName = "unix" }) }, | |
{ key = "w", mods = CMD, action = act.CloseCurrentTab({ confirm = false }) }, | |
{ key = "LeftArrow", mods = "SHIFT", action = act.ActivateTabRelative(-1) }, | |
{ key = "RightArrow", mods = "SHIFT", action = act.ActivateTabRelative(1) }, | |
{ key = "w", mods = "LEADER", action = act.ShowLauncherArgs({ flags = "FUZZY|WORKSPACES" }) }, | |
{ key = "z", mods = "LEADER", action = act.TogglePaneZoomState }, | |
{ | |
key = "r", | |
mods = "LEADER", | |
action = act.PromptInputLine({ | |
description = "Enter new name for workspace", | |
action = wezterm.action_callback(function(window, pane, line) | |
if line then | |
mux.rename_workspace(mux.get_active_workspace(), line) | |
end | |
end), | |
}), | |
}, | |
{ | |
key = "W", | |
mods = "LEADER|SHIFT", | |
action = act.PromptInputLine({ | |
description = wezterm.format({ | |
{ Text = "Enter name for new workspace" }, | |
}), | |
action = wezterm.action_callback(function(window, pane, line) | |
if line then | |
window:perform_action(act.SwitchToWorkspace({ name = line }), pane) | |
end | |
end), | |
}), | |
}, | |
{ key = "L", mods = CMD, action = wezterm.action.ShowDebugOverlay }, | |
} | |
for i = 1, 8 do | |
-- CMD + number to activate that tab | |
table.insert(config.keys, { | |
key = tostring(i), | |
mods = CMD, | |
action = act.ActivateTab(i - 1), | |
}) | |
-- CMD+ALT + number to move to that position | |
table.insert(config.keys, { | |
key = tostring(i), | |
mods = CMD .. "|ALT", | |
action = act.MoveTab(i - 1), | |
}) | |
end | |
if not isWin then | |
-- config.font = wezterm.font("Mononoki Nerd Font") | |
config.font = wezterm.font("JetBrainsMono Nerd Font") | |
-- config.font = wezterm.font("MonaspiceKr Nerd Font") | |
end | |
wezterm.on("format-tab-title", function(tab) | |
local icon = tab.is_active and wezterm.nerdfonts.md_tab or wezterm.nerdfonts.md_tab_unselected | |
return { | |
{ Text = icon .. " " .. tab.tab_index + 1 .. ":" .. tab.active_pane.pane_index .. " " }, | |
} | |
end) | |
return config |
This file contains hidden or 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
[colors] | |
ansi = [ | |
"#1c1c1c", # Black | |
"#f55e67", # Red | |
"#5faf5f", # Green | |
"#e68455", # Yellow | |
"#8797f6", # Blue | |
"#af5faf", # Magenta | |
"#00b5ae", # Cyan | |
"#949598", # White | |
] | |
brights = [ | |
"#333333", # Black | |
"#f55e67", # Red | |
"#5faf5f", # Green | |
"#e68455", # Yellow | |
"#8797f6", # Blue | |
"#af5faf", # Magenta | |
"#00b5ae", # Cyan | |
"#ecf7ec", # White | |
] | |
foreground = "#ecf7ec" | |
background = "#121212" | |
cursor_fg = "#ecf7ec" | |
cursor_border = "#949598" | |
compose_cursor = '#e68455' | |
selection_fg = 'none' | |
selection_bg = 'rgba(50% 50% 50% 45%)' | |
split = '#1c1c1c' | |
[colors.tab_bar] | |
inactive_tab_edge = "#ff00d7" | |
background = "transparent" | |
[colors.tab_bar.active_tab] | |
fg_color = "#5faf5f" | |
bg_color = "transparent" | |
[colors.tab_bar.inactive_tab] | |
fg_color = "#949598" | |
bg_color = "transparent" | |
[colors.tab_bar.inactive_tab_hover] | |
fg_color = "#ecf7ec" | |
bg_color = "transparent" | |
[metadata] | |
aliases = [] | |
author = "Daniel Brüggemann (https://danbruegge.com)" | |
name = "Kong" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment