From c61a406d1748749c5fd82de561b803eebb3ba077 Mon Sep 17 00:00:00 2001 From: Sergei Bulavintsev Date: Wed, 7 Feb 2024 14:38:01 +0300 Subject: [PATCH] feat(wezterm): finally fix fonts, clean config --- .../nixos/desktop/addons/wezterm/colors.lua | 48 +++++++ .../nixos/desktop/addons/wezterm/default.nix | 2 + .../nixos/desktop/addons/wezterm/mappings.lua | 23 ++-- .../nixos/desktop/addons/wezterm/tabs.lua | 26 ++-- .../nixos/desktop/addons/wezterm/wezterm.lua | 128 +++++++----------- 5 files changed, 121 insertions(+), 106 deletions(-) create mode 100644 nix/modules/nixos/desktop/addons/wezterm/colors.lua diff --git a/nix/modules/nixos/desktop/addons/wezterm/colors.lua b/nix/modules/nixos/desktop/addons/wezterm/colors.lua new file mode 100644 index 0000000..74eae89 --- /dev/null +++ b/nix/modules/nixos/desktop/addons/wezterm/colors.lua @@ -0,0 +1,48 @@ +local base16_colors = { + bg = "#1B2B34", + bg_dark = "#343D46", + bg_highlight = "#4F5B66", + comment = "#65737E", + fg_dark = "#A7ADBA", + fg = "#C0C5CE", + fg_gutter = "#CDD3DE", + fg_light = "#D8DEE9", -- TODO: this doesn't make sesne + + red = "#EC5f67", + orange = "#F99157", + yellow = "#FAC863", + green = "#99C794", + green_dark = "#11ab49", + cyan = "#5FB3B3", + blue = "#6699CC", + purple = "#C594C5", + magenta = "#C594C5", + black = "#000000", + white = "#dedcdc", +} + +-- config.color_scheme = "Oceanic-Next" +command_palette_bg_color = base16_colors.black +-- https://wezfurlong.org/wezterm/config/appearance.html#retro-tab-bar-appearance +config.colors = { + -- The default text color + foreground = base16_colors.white, + -- The default background color + background = base16_colors.black, + tab_bar = { + background = base16_colors.black, + active_tab = { + bg_color = base16_colors.green_dark, + fg_color = base16_colors.fg, + }, + inactive_tab = { + -- bg_color = base16_colors.bg_dark, + bg_color = base16_colors.bg_dark, + fg_color = base16_colors.fg_dark, + }, + new_tab = { + bg_color = base16_colors.bg_dark, + fg_color = base16_colors.fg_dark, + }, + }, +} diff --git a/nix/modules/nixos/desktop/addons/wezterm/default.nix b/nix/modules/nixos/desktop/addons/wezterm/default.nix index 3fa0d41..d5fd69b 100644 --- a/nix/modules/nixos/desktop/addons/wezterm/default.nix +++ b/nix/modules/nixos/desktop/addons/wezterm/default.nix @@ -17,8 +17,10 @@ in { home.programs.wezterm = { enable = true; extraConfig = + # Generate wezterm.lua; order of files are important (builtins.readFile ./wezterm.lua) + (builtins.readFile ./mappings.lua) + + (builtins.readFile ./colors.lua) + (builtins.readFile ./tabs.lua) + '' return config diff --git a/nix/modules/nixos/desktop/addons/wezterm/mappings.lua b/nix/modules/nixos/desktop/addons/wezterm/mappings.lua index 5fb5df7..c12e911 100644 --- a/nix/modules/nixos/desktop/addons/wezterm/mappings.lua +++ b/nix/modules/nixos/desktop/addons/wezterm/mappings.lua @@ -1,3 +1,5 @@ +local act = wezterm.action + config.leader = { key = "b", mods = "CTRL" } config.keys = { @@ -17,7 +19,6 @@ config.keys = { action = act.CloseCurrentPane { confirm = true }, }, { key = "X", mods = "LEADER", action = act.ActivateCopyMode }, - { key = "Z", mods = "LEADER", action = act.TogglePaneZoomState }, { key = "p", mods = "LEADER", action = act.ActivateTabRelative(-1) }, { key = "n", mods = "LEADER", action = act.ActivateTabRelative(1) }, @@ -45,19 +46,13 @@ config.keys = { { key = "7", mods = "LEADER", action = wezterm.action { ActivateTab = 6 } }, { key = "8", mods = "LEADER", action = wezterm.action { ActivateTab = 7 } }, { key = "9", mods = "LEADER", action = wezterm.action { ActivateTab = 8 } }, - { key = "&", mods = "LEADER|SHIFT", action = wezterm.action { CloseCurrentTab = { confirm = true } } }, { key = "d", mods = "LEADER", action = wezterm.action { CloseCurrentPane = { confirm = true } } }, - { key = "x", mods = "LEADER", action = wezterm.action { CloseCurrentPane = { confirm = true } } }, - - -- -- move between split panes - -- split_nav("move", "h"), - -- split_nav("move", "j"), - -- split_nav("move", "k"), - -- split_nav("move", "l"), +} - -- -- resize panes - -- split_nav("resize", "h"), - -- split_nav("resize", "j"), - -- split_nav("resize", "k"), - -- split_nav("resize", "l"), +config.mouse_bindings = { + { + event = { Down = { streak = 1, button = "Right" } }, + mods = "NONE", + action = act.PasteFrom "PrimarySelection", + }, } diff --git a/nix/modules/nixos/desktop/addons/wezterm/tabs.lua b/nix/modules/nixos/desktop/addons/wezterm/tabs.lua index d44cadb..fe6e638 100644 --- a/nix/modules/nixos/desktop/addons/wezterm/tabs.lua +++ b/nix/modules/nixos/desktop/addons/wezterm/tabs.lua @@ -15,22 +15,22 @@ local icons = { ["git"] = wezterm.nerdfonts.dev_git, ["go"] = wezterm.nerdfonts.seti_go, ["htop"] = wezterm.nerdfonts.md_chart_areaspline, - ["kubectl"] = wezterm.nerdfonts.linux_docker, - ["k9s"] = wezterm.nerdfonts.linux_docker, + ["kubectl"] = wezterm.nerdfonts.md_kubernetes, + ["k9s"] = wezterm.nerdfonts.md_kubernetes, ["kuberlr"] = wezterm.nerdfonts.linux_docker, ["lazydocker"] = wezterm.nerdfonts.linux_docker, ["lazygit"] = wezterm.nerdfonts.cod_github, ["lua"] = wezterm.nerdfonts.seti_lua, ["make"] = wezterm.nerdfonts.seti_makefile, ["node"] = wezterm.nerdfonts.mdi_hexagon, - ["nvim"] = wezterm.nerdfonts.custom_vim, - ["pacman"] = "󰮯 ", - ["paru"] = "󰮯 ", + ["nvim"] = wezterm.nerdfonts.linux_neovim, + ["nix"] = wezterm.nerdfonts.md_nix, + ["nixt"] = wezterm.nerdfonts.md_nix, ["psql"] = wezterm.nerdfonts.dev_postgresql, ["pwsh.exe"] = wezterm.nerdfonts.md_console, ["ruby"] = wezterm.nerdfonts.cod_ruby, ["sudo"] = wezterm.nerdfonts.fa_hashtag, - ["vim"] = wezterm.nerdfonts.dev_vim, + ["vim"] = wezterm.nerdfonts.linux_neovim, ["wget"] = wezterm.nerdfonts.mdi_arrow_down_box, ["zsh"] = wezterm.nerdfonts.dev_terminal, } @@ -67,13 +67,13 @@ wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_wid local inactive_bg = colors.tab_bar.inactive_tab.bg_color local tab_idx = 1 - -- for i, t in ipairs(tabs) do - -- if t.tab_id == tab.tab_id then - -- tab_idx = i - -- break - -- end - -- end - local tab_idx = tab.tab_index + 1 + for i, t in ipairs(tabs) do + if t.tab_id == tab.tab_id then + tab_idx = i + break + end + end + -- local tab_idx = tab.tab_index + 1 local is_last = tab_idx == #tabs local next_tab = tabs[tab_idx + 1] local next_is_active = next_tab and next_tab.is_active diff --git a/nix/modules/nixos/desktop/addons/wezterm/wezterm.lua b/nix/modules/nixos/desktop/addons/wezterm/wezterm.lua index c9f47da..ac4bf34 100644 --- a/nix/modules/nixos/desktop/addons/wezterm/wezterm.lua +++ b/nix/modules/nixos/desktop/addons/wezterm/wezterm.lua @@ -1,109 +1,54 @@ -- https://github.com/pjcj/base/blob/2f036f8bb616a5b3dabf8314ae9eb6d574a83e32/.wezterm.lua#L406 -- local wezterm = require "wezterm" -local act = wezterm.action local config = {} if wezterm.config_builder then config = wezterm.config_builder() end --- https://wezfurlong.org/wezterm/config/lua/window-events/update-right-status.html -wezterm.on("update-right-status", function(window) - window:set_right_status(wezterm.format { - { Text = wezterm.strftime "[%H:%M]" }, - }) -end) - -local font_family = "CaskaydiaCove Nerd Font Mono" +-- Fonts +-- {{{ config.adjust_window_size_when_changing_font_size = false --- wezterm comes with JetBrains Mono and a default fallback font for symbols --- so technically, this is not needed. But the fallback symbols are a bit odd --- looking compared to JetBrains Mono (seem too big or stretched out) config.font = wezterm.font_with_fallback { - { family = font_family, weight = "Regular", stretch = "Normal", style = "Normal" }, - { family = font_family, weight = "Regular", stretch = "Normal", style = "Italic" }, - { family = font_family, weight = "Bold", stretch = "Normal", style = "Normal" }, - { family = font_family, weight = "Bold", stretch = "Normal", style = "Italic" }, + "CaskaydiaCove Nerd Font Mono", + { family = "Symbols Nerd Font Mono", scale = 0.9 }, + { family = "DejaVu Sans", weight = "Regular", scale = 0.75 }, } - --- config.font = wezterm.font("CaskaydiaCove Nerd Font", { --- weight = "Regular", --- }) config.font_size = 14 +-- }}} +-- Windows +-- {{{ +config.window_close_confirmation = "AlwaysPrompt" config.window_padding = { left = 0, right = 0, top = 1, - bottom = 1, + bottom = 0, } -config.xcursor_theme = "Adwaita" config.window_background_opacity = 0.9 +-- }}} +-- Cursor +-- {{{ +config.cursor_blink_rate = 1000 +config.default_cursor_style = "BlinkingBlock" +config.hide_mouse_cursor_when_typing = false +config.xcursor_theme = "Adwaita" +-- }}} +-- Tabs +-- {{{ config.use_fancy_tab_bar = false +config.tab_max_width = 32 config.hide_tab_bar_if_only_one_tab = false config.tab_bar_at_bottom = true -config.tab_max_width = 64 -config.hide_mouse_cursor_when_typing = false --- config.color_scheme = "Oceanic-Next" -config.cursor_blink_rate = 1000 -config.command_palette_bg_color = "#1c1c1c" -config.default_cursor_style = "BlinkingBlock" - --- Never prompt confirmation for closing --- config.window_close_confirmation = "NeverPrompt" -config.window_close_confirmation = "AlwaysPrompt" - -local base16_colors = { - bg = "#1B2B34", - bg_dark = "#343D46", - bg_highlight = "#4F5B66", - comment = "#65737E", - fg_dark = "#A7ADBA", - fg = "#C0C5CE", - fg_gutter = "#CDD3DE", - fg_light = "#D8DEE9", -- TODO: this doesn't make sesne - - red = "#EC5f67", - orange = "#F99157", - yellow = "#FAC863", - green = "#99C794", - green_dark = "#11ab49", - cyan = "#5FB3B3", - blue = "#6699CC", - purple = "#C594C5", - magenta = "#C594C5", - black = "#000000", -} - --- https://wezfurlong.org/wezterm/config/appearance.html#retro-tab-bar-appearance -config.colors = { - -- The default text color - foreground = "white", - -- The default background color - background = "black", - tab_bar = { - background = base16_colors.bg, - active_tab = { - bg_color = base16_colors.green_dark, - fg_color = base16_colors.fg, - }, - inactive_tab = { - bg_color = base16_colors.bg_dark, - fg_color = base16_colors.fg_dark, - }, - new_tab = { - bg_color = base16_colors.bg_dark, - fg_color = base16_colors.fg_dark, - }, - }, -} - config.inactive_pane_hsb = { saturation = 0.9, brightness = 0.2, } - +-- }}} +-- Update window title +-- {{{ wezterm.on("format-window-title", function(tab, _, tabs) local index = "" if #tabs > 1 then @@ -112,3 +57,28 @@ wezterm.on("format-window-title", function(tab, _, tabs) return index .. tab.window_title end) +-- }}} +-- Update status on the right side +-- {{{ +-- Icons: https://wezfurlong.org/wezterm/config/lua/wezterm/nerdfonts.html +-- https://wezfurlong.org/wezterm/config/lua/window-events/update-right-status.html +wezterm.on("update-right-status", function(window) + local _, kube_context, _ = wezterm.run_child_process { "bash", "-lc", "kubectx -c" } + local _, kube_ns, _ = wezterm.run_child_process { "bash", "-lc", "kubens -c" } + kube_context = kube_context:gsub("[\n\r]", "") + kube_ns = kube_ns:gsub("[\n\r]", "") + + local date = wezterm.strftime "[%H:%M]" + + window:set_right_status(wezterm.format { + { Foreground = { Color = base16_colors.blue } }, + { Text = wezterm.nerdfonts.md_kubernetes }, + { Foreground = { Color = base16_colors.magenta } }, + { Text = " " .. kube_context }, + { Foreground = { Color = base16_colors.cyan } }, + { Text = ":" .. kube_ns }, + { Foreground = { Color = base16_colors.red } }, + { Text = " " .. date }, + }) +end) +-- }}}