From 2629d175bc9dd95cfe2dcf3d26bba6b9c1e6bc77 Mon Sep 17 00:00:00 2001 From: winston Date: Thu, 9 Feb 2023 17:18:50 +0100 Subject: [PATCH] feat(wezterm): toggleable tab bar, reformat with stylua --- modules/wezterm.nix | 4 +- modules/wezterm/.stylua.toml | 7 + modules/wezterm/fonts.lua | 5 +- modules/wezterm/shortcuts.lua | 345 ++++++++++++++++++---------------- modules/wezterm/wezterm.lua | 88 +++++---- 5 files changed, 234 insertions(+), 215 deletions(-) create mode 100644 modules/wezterm/.stylua.toml diff --git a/modules/wezterm.nix b/modules/wezterm.nix index 8a43a61..fc07e4b 100644 --- a/modules/wezterm.nix +++ b/modules/wezterm.nix @@ -1,9 +1,9 @@ -{ config, ... }: +{ config, machine, ... }: { xdg.configFile = { "wezterm" = { - source = config.lib.file.mkOutOfStoreSymlink ./wezterm; + source = config.lib.file.mkOutOfStoreSymlink "${machine.flakePath}/modules/wezterm"; recursive = true; }; }; diff --git a/modules/wezterm/.stylua.toml b/modules/wezterm/.stylua.toml new file mode 100644 index 0000000..4d49284 --- /dev/null +++ b/modules/wezterm/.stylua.toml @@ -0,0 +1,7 @@ +column_width = 80 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferDouble" +collapse_simple_statement = "Never" +call_parentheses = "Always" diff --git a/modules/wezterm/fonts.lua b/modules/wezterm/fonts.lua index 6bb51e7..3f562fa 100644 --- a/modules/wezterm/fonts.lua +++ b/modules/wezterm/fonts.lua @@ -32,7 +32,10 @@ M.get_font = function(name) } return { - font = wezterm.font(fonts[name].font), + font = wezterm.font_with_fallback({ + fonts[name].font, + "Symbols Nerd Font", + }), size = fonts[name].size, } end diff --git a/modules/wezterm/shortcuts.lua b/modules/wezterm/shortcuts.lua index 13c0ece..c29f84d 100644 --- a/modules/wezterm/shortcuts.lua +++ b/modules/wezterm/shortcuts.lua @@ -2,178 +2,189 @@ local wezterm = require("wezterm") local act = wezterm.action return { - -- use 'Backslash' to split horizontally - { - key = "\\", - mods = "LEADER", - action = act.SplitHorizontal({ domain = "CurrentPaneDomain" }), - }, - -- and 'Minus' to split vertically - { - key = "-", - mods = "LEADER", - action = act.SplitVertical({ domain = "CurrentPaneDomain" }), - }, - -- 'hjkl' to move between panes - { key = "h", mods = "LEADER", action = act.ActivatePaneDirection("Left") }, - { key = "j", mods = "LEADER", action = act.ActivatePaneDirection("Down") }, - { key = "k", mods = "LEADER", action = act.ActivatePaneDirection("Up") }, - { key = "l", mods = "LEADER", action = act.ActivatePaneDirection("Right") }, - -- -- Shift + 'hjkl' to resize panes - { - key = "h", - mods = "LEADER|SHIFT", - action = act.AdjustPaneSize({ "Left", 5 }), - }, - { - key = "j", - mods = "LEADER|SHIFT", - action = act.AdjustPaneSize({ "Down", 5 }), - }, - { - key = "k", - mods = "LEADER|SHIFT", - action = act.AdjustPaneSize({ "Up", 5 }), - }, - { - key = "l", - mods = "LEADER|SHIFT", - action = act.AdjustPaneSize({ "Right", 5 }), - }, - -- numbers to navigate to tabs - { key = "1", mods = "LEADER", action = act.ActivateTab(0) }, - { key = "2", mods = "LEADER", action = act.ActivateTab(1) }, - { key = "3", mods = "LEADER", action = act.ActivateTab(2) }, - { key = "4", mods = "LEADER", action = act.ActivateTab(3) }, - { key = "5", mods = "LEADER", action = act.ActivateTab(4) }, - { key = "6", mods = "LEADER", action = act.ActivateTab(5) }, - { key = "7", mods = "LEADER", action = act.ActivateTab(6) }, - { key = "8", mods = "LEADER", action = act.ActivateTab(7) }, - { key = "9", mods = "LEADER", action = act.ActivateTab(8) }, - { key = "9", mods = "LEADER", action = act.ActivateTab(9) }, - { key = "0", mods = "LEADER", action = act.ActivateTab(-1) }, - { key = "1", mods = "SUPER", action = act.ActivateTab(0) }, - { key = "2", mods = "SUPER", action = act.ActivateTab(1) }, - { key = "3", mods = "SUPER", action = act.ActivateTab(2) }, - { key = "4", mods = "SUPER", action = act.ActivateTab(3) }, - { key = "5", mods = "SUPER", action = act.ActivateTab(4) }, - { key = "6", mods = "SUPER", action = act.ActivateTab(5) }, - { key = "7", mods = "SUPER", action = act.ActivateTab(6) }, - { key = "8", mods = "SUPER", action = act.ActivateTab(7) }, - { key = "9", mods = "SUPER", action = act.ActivateTab(8) }, - { key = "9", mods = "SUPER", action = act.ActivateTab(9) }, - { key = "0", mods = "SUPER", action = act.ActivateTab(-1) }, - -- 'c' to create a new tab - { key = "c", mods = "LEADER", action = act.SpawnTab("CurrentPaneDomain") }, - -- 'x' to kill the current pane - { - key = "x", - mods = "LEADER", - action = act.CloseCurrentPane({ confirm = true }), - }, - -- 'z' to toggle the zoom for the current pane - { key = "z", mods = "LEADER", action = "TogglePaneZoomState" }, - -- 'v' to visually select in the current pane - { key = "v", mods = "LEADER", action = "ActivateCopyMode" }, - -- 'r' to rotate panes - { key = "r", mods = "LEADER", action = act.RotatePanes("Clockwise") }, - { key = " ", mods = "LEADER", action = act.QuickSelect }, - { - key = "o", - mods = "LEADER", - action = act.QuickSelectArgs({ - label = "open url", - patterns = { - "https?://\\S+", - }, - action = wezterm.action_callback(function(window, pane) - local url = window:get_selection_text_for_pane(pane) - wezterm.open_with(url) - end), - }), - }, - -- copypasta - { key = "Enter", mods = "ALT", action = act.ToggleFullScreen }, + -- use 'Backslash' to split horizontally + { + key = "\\", + mods = "LEADER", + action = act.SplitHorizontal({ domain = "CurrentPaneDomain" }), + }, + -- and 'Minus' to split vertically + { + key = "-", + mods = "LEADER", + action = act.SplitVertical({ domain = "CurrentPaneDomain" }), + }, + -- 'hjkl' to move between panes + { key = "h", mods = "LEADER", action = act.ActivatePaneDirection("Left") }, + { key = "j", mods = "LEADER", action = act.ActivatePaneDirection("Down") }, + { key = "k", mods = "LEADER", action = act.ActivatePaneDirection("Up") }, + { key = "l", mods = "LEADER", action = act.ActivatePaneDirection("Right") }, + -- -- Shift + 'hjkl' to resize panes + { + key = "h", + mods = "LEADER|SHIFT", + action = act.AdjustPaneSize({ "Left", 5 }), + }, + { + key = "j", + mods = "LEADER|SHIFT", + action = act.AdjustPaneSize({ "Down", 5 }), + }, + { + key = "k", + mods = "LEADER|SHIFT", + action = act.AdjustPaneSize({ "Up", 5 }), + }, + { + key = "l", + mods = "LEADER|SHIFT", + action = act.AdjustPaneSize({ "Right", 5 }), + }, + -- numbers to navigate to tabs + { key = "1", mods = "LEADER", action = act.ActivateTab(0) }, + { key = "2", mods = "LEADER", action = act.ActivateTab(1) }, + { key = "3", mods = "LEADER", action = act.ActivateTab(2) }, + { key = "4", mods = "LEADER", action = act.ActivateTab(3) }, + { key = "5", mods = "LEADER", action = act.ActivateTab(4) }, + { key = "6", mods = "LEADER", action = act.ActivateTab(5) }, + { key = "7", mods = "LEADER", action = act.ActivateTab(6) }, + { key = "8", mods = "LEADER", action = act.ActivateTab(7) }, + { key = "9", mods = "LEADER", action = act.ActivateTab(8) }, + { key = "9", mods = "LEADER", action = act.ActivateTab(9) }, + { key = "0", mods = "LEADER", action = act.ActivateTab(-1) }, + { key = "1", mods = "SUPER", action = act.ActivateTab(0) }, + { key = "2", mods = "SUPER", action = act.ActivateTab(1) }, + { key = "3", mods = "SUPER", action = act.ActivateTab(2) }, + { key = "4", mods = "SUPER", action = act.ActivateTab(3) }, + { key = "5", mods = "SUPER", action = act.ActivateTab(4) }, + { key = "6", mods = "SUPER", action = act.ActivateTab(5) }, + { key = "7", mods = "SUPER", action = act.ActivateTab(6) }, + { key = "8", mods = "SUPER", action = act.ActivateTab(7) }, + { key = "9", mods = "SUPER", action = act.ActivateTab(8) }, + { key = "9", mods = "SUPER", action = act.ActivateTab(9) }, + { key = "0", mods = "SUPER", action = act.ActivateTab(-1) }, + -- 'c' to create a new tab + { key = "c", mods = "LEADER", action = act.SpawnTab("CurrentPaneDomain") }, + -- 'x' to kill the current pane + { + key = "x", + mods = "LEADER", + action = act.CloseCurrentPane({ confirm = true }), + }, + -- 'z' to toggle the zoom for the current pane + { key = "z", mods = "LEADER", action = "TogglePaneZoomState" }, + -- 'Z' to hide the tab bar (useful for screenshots) + { + key = "Z", + mods = "LEADER", + action = wezterm.action_callback(function(window) + wezterm.GLOBAL.enable_tab_bar = not wezterm.GLOBAL.enable_tab_bar + window:set_config_overrides({ + enable_tab_bar = wezterm.GLOBAL.enable_tab_bar, + }) + end), + }, + -- 'v' to visually select in the current pane + { key = "v", mods = "LEADER", action = "ActivateCopyMode" }, + -- 'r' to rotate panes + { key = "r", mods = "LEADER", action = act.RotatePanes("Clockwise") }, + { key = " ", mods = "LEADER", action = act.QuickSelect }, + { + key = "o", + mods = "LEADER", + action = act.QuickSelectArgs({ + label = "open url", + patterns = { + "https?://\\S+", + }, + action = wezterm.action_callback(function(window, pane) + local url = window:get_selection_text_for_pane(pane) + wezterm.open_with(url) + end), + }), + }, + -- copypasta + { key = "Enter", mods = "ALT", action = act.ToggleFullScreen }, - { key = "-", mods = "CTRL", action = act.DecreaseFontSize }, - { key = "-", mods = "SUPER", action = act.DecreaseFontSize }, - { key = "=", mods = "CTRL", action = act.IncreaseFontSize }, - { key = "=", mods = "SUPER", action = act.IncreaseFontSize }, - { key = "0", mods = "CTRL", action = act.ResetFontSize }, - { key = "0", mods = "SUPER", action = act.ResetFontSize }, + { key = "-", mods = "CTRL", action = act.DecreaseFontSize }, + { key = "-", mods = "SUPER", action = act.DecreaseFontSize }, + { key = "=", mods = "CTRL", action = act.IncreaseFontSize }, + { key = "=", mods = "SUPER", action = act.IncreaseFontSize }, + { key = "0", mods = "CTRL", action = act.ResetFontSize }, + { key = "0", mods = "SUPER", action = act.ResetFontSize }, - { key = "c", mods = "SHIFT|CTRL", action = act.CopyTo("Clipboard") }, - { key = "c", mods = "SUPER", action = act.CopyTo("Clipboard") }, - { key = "v", mods = "SHIFT|CTRL", action = act.PasteFrom("Clipboard") }, - { key = "v", mods = "SUPER", action = act.PasteFrom("Clipboard") }, + { key = "c", mods = "SHIFT|CTRL", action = act.CopyTo("Clipboard") }, + { key = "c", mods = "SUPER", action = act.CopyTo("Clipboard") }, + { key = "v", mods = "SHIFT|CTRL", action = act.PasteFrom("Clipboard") }, + { key = "v", mods = "SUPER", action = act.PasteFrom("Clipboard") }, - { - key = "f", - mods = "SHIFT|CTRL", - action = act.Search("CurrentSelectionOrEmptyString"), - }, - { - key = "f", - mods = "SUPER", - action = act.Search("CurrentSelectionOrEmptyString"), - }, + { + key = "f", + mods = "SHIFT|CTRL", + action = act.Search("CurrentSelectionOrEmptyString"), + }, + { + key = "f", + mods = "SUPER", + action = act.Search("CurrentSelectionOrEmptyString"), + }, - { key = "l", mods = "SHIFT|CTRL", action = act.ShowDebugOverlay }, + { key = "l", mods = "SHIFT|CTRL", action = act.ShowDebugOverlay }, - { - key = "p", - mods = "LEADER", - action = act.PaneSelect({ alphabet = "asdfghjkl;", mode = "Activate" }), - }, - { - key = "P", - mods = "LEADER", - action = act.PaneSelect({ - alphabet = "asdfghjkl;", - mode = "SwapWithActive", - }), - }, + { + key = "p", + mods = "LEADER", + action = act.PaneSelect({ alphabet = "asdfghjkl;", mode = "Activate" }), + }, + { + key = "P", + mods = "LEADER", + action = act.PaneSelect({ + alphabet = "asdfghjkl;", + mode = "SwapWithActive", + }), + }, - { - key = "p", - mods = "SUPER", - action = act.PaneSelect({ alphabet = "asdfghjkl;", mode = "Activate" }), - }, - { - key = "P", - mods = "SUPER", - action = act.PaneSelect({ - alphabet = "asdfghjkl;", - mode = "SwapWithActive", - }), - }, - { key = "R", mods = "LEADER", action = act.ReloadConfiguration }, + { + key = "p", + mods = "SUPER", + action = act.PaneSelect({ alphabet = "asdfghjkl;", mode = "Activate" }), + }, + { + key = "P", + mods = "SUPER", + action = act.PaneSelect({ + alphabet = "asdfghjkl;", + mode = "SwapWithActive", + }), + }, + { key = "R", mods = "LEADER", action = act.ReloadConfiguration }, - -- mostly OS defaults - { key = "n", mods = "SHIFT|CTRL", action = act.SpawnWindow }, - { key = "n", mods = "SUPER", action = act.SpawnWindow }, - { - key = "t", - mods = "SHIFT|CTRL", - action = act.SpawnTab("CurrentPaneDomain"), - }, - { key = "t", mods = "SUPER", action = act.SpawnTab("CurrentPaneDomain") }, - { - key = "w", - mods = "SHIFT|CTRL", - action = act.CloseCurrentTab({ confirm = true }), - }, - { - key = "w", - mods = "SUPER", - action = act.CloseCurrentTab({ confirm = true }), - }, - { - key = "u", - mods = "SHIFT|CTRL", - action = act.CharSelect({ - copy_on_select = true, - copy_to = "ClipboardAndPrimarySelection", - }), - }, + -- mostly OS defaults + { key = "n", mods = "SHIFT|CTRL", action = act.SpawnWindow }, + { key = "n", mods = "SUPER", action = act.SpawnWindow }, + { + key = "t", + mods = "SHIFT|CTRL", + action = act.SpawnTab("CurrentPaneDomain"), + }, + { key = "t", mods = "SUPER", action = act.SpawnTab("CurrentPaneDomain") }, + { + key = "w", + mods = "SHIFT|CTRL", + action = act.CloseCurrentTab({ confirm = true }), + }, + { + key = "w", + mods = "SUPER", + action = act.CloseCurrentTab({ confirm = true }), + }, + { + key = "u", + mods = "SHIFT|CTRL", + action = act.CharSelect({ + copy_on_select = true, + copy_to = "ClipboardAndPrimarySelection", + }), + }, } diff --git a/modules/wezterm/wezterm.lua b/modules/wezterm/wezterm.lua index 9e67d99..46426fc 100644 --- a/modules/wezterm/wezterm.lua +++ b/modules/wezterm/wezterm.lua @@ -1,54 +1,52 @@ local wezterm = require("wezterm") local fonts = require("fonts") local theme = require("theme") +local shortcuts = require("shortcuts") require("bar") local font = fonts.get_font("berkeley") - --- wezterm.GLOBAL.smart_padding = { --- left = 12, --- right = 12, --- top = 0, --- bottom = 0, --- } +wezterm.GLOBAL = { + enable_tab_bar = true, +} return { - -- keys - disable_default_key_bindings = true, - leader = { key = "s", mods = "CTRL", timeout_milliseconds = 5000 }, - keys = require("shortcuts"), - -- font - font = font.font, - font_size = font.size, - -- window - window_decorations = "RESIZE", - window_padding = { - left = 0, - right = 0, - top = 0, - bottom = 0, - }, - inactive_pane_hsb = { - saturation = 1.0, - brightness = 0.6, - }, - -- theme - color_schemes = theme.get_custom_colorschemes(), - color_scheme = theme.scheme_for_appearance(wezterm.gui.get_appearance(), { - dark = "OLEDppuccin", - light = "Catppuccin Latte", - }), - -- tab bar - tab_bar_at_bottom = true, - tab_max_width = 32, - use_fancy_tab_bar = false, - window_background_opacity = 1.00, - -- hide_tab_bar_if_only_one_tab = true, - -- etc. - adjust_window_size_when_changing_font_size = false, - use_resize_increments = false, - audible_bell = "Disabled", - clean_exit_codes = { 130 }, - default_cursor_style = "BlinkingBar", - enable_scroll_bar = false, + -- keys + disable_default_key_bindings = true, + leader = { key = "s", mods = "CTRL", timeout_milliseconds = 5000 }, + keys = shortcuts, + -- font + font = font.font, + font_size = font.size, + -- window + window_decorations = "RESIZE", + window_padding = { + left = 0, + right = 0, + top = 0, + bottom = 0, + }, + inactive_pane_hsb = { + saturation = 1.0, + brightness = 0.6, + }, + -- theme + color_schemes = theme.get_custom_colorschemes(), + color_scheme = theme.scheme_for_appearance(wezterm.gui.get_appearance(), { + dark = "OLEDppuccin", + light = "Catppuccin Latte", + }), + -- tab bar + tab_bar_at_bottom = true, + tab_max_width = 32, + use_fancy_tab_bar = false, + window_background_opacity = 1.00, + hide_tab_bar_if_only_one_tab = false, + enable_tab_bar = wezterm.GLOBAL.tab_bar_hidden, + -- etc. + adjust_window_size_when_changing_font_size = false, + use_resize_increments = false, + audible_bell = "Disabled", + clean_exit_codes = { 130 }, + default_cursor_style = "BlinkingBar", + enable_scroll_bar = false, }