From ff6443e1454e56d475d2caea135bd2a1e6d67c70 Mon Sep 17 00:00:00 2001 From: rootiest Date: Fri, 4 Oct 2024 12:44:54 -0400 Subject: [PATCH] feat: user customization for tabline -- feat: Allows for user overrides to customize the tabline appearance -- fix: Hide battery component in default tabline layout when no batteries are found --- README.md | 59 +++++++++++++++++++++++++++++++++++++++++++++ opts.lua | 1 + plugins/tabline.lua | 18 +++++++++++--- 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7029424..460dc53 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,8 @@ The rootiest WezTerm configuration you will ever see! User customizations can be added by creating a `user.lua` file in the `~/.config/wezterm` directory. +### General Configuration + The file should be structured in the following manner: ```lua @@ -142,6 +144,63 @@ These global variables will be detected and used to apply the encryption. As with the default configuration, if the keyfile is not found, encryption is disabled. +### Tabline Customization + +The tabline configuration can also be customized. + +This is done by adding (above the `return{}` table): + +```lua +local wezterm = WEZTERM -- Link to the main wezterm object + +MYTABLINE = { + options = { + icons_enabled = true, + theme = 'Catppuccin Mocha', + color_overrides = {}, + section_separators = { + left = wezterm.nerdfonts.pl_left_hard_divider, + right = wezterm.nerdfonts.pl_right_hard_divider, + }, + component_separators = { + left = wezterm.nerdfonts.pl_left_soft_divider, + right = wezterm.nerdfonts.pl_right_soft_divider, + }, + tab_separators = { + left = wezterm.nerdfonts.pl_left_hard_divider, + right = wezterm.nerdfonts.pl_right_hard_divider, + }, + }, + sections = { + tabline_a = { 'mode' }, + tabline_b = { 'workspace' }, + tabline_c = { ' ' }, + tab_active = { + 'index', + { 'parent', padding = 0 }, + '/', + { 'cwd', padding = { left = 0, right = 1 } }, + { 'zoomed', padding = 0 }, + }, + tab_inactive = { 'index', { 'process', padding = { left = 0, right = 1 } } }, + tabline_x = { 'ram', 'cpu' }, + tabline_y = { 'datetime', 'battery' }, + tabline_z = { 'hostname' }, + }, + extensions = {}, +} + +return { + -- Etc.. +} +``` + +The table above is taken from the example in the +[tabline.wez documentation](https://github.com/michaelbrusegard/tabline.wez?tab=readme-ov-file#default-configuration). + +This is the table that will be passed to `tabline.setup()` +and loaded by the tabline plugin. + ## Screenshots ![Rootiest WezTerm](.screenshots/term.png) diff --git a/opts.lua b/opts.lua index 8556cb5..52d208c 100644 --- a/opts.lua +++ b/opts.lua @@ -33,6 +33,7 @@ if USERCONFIG then else MYKEY = nil MYPUBKEY = nil + MYTAB_BAR = nil end -- Return config options table diff --git a/plugins/tabline.lua b/plugins/tabline.lua index e8e69fd..8f84aa6 100644 --- a/plugins/tabline.lua +++ b/plugins/tabline.lua @@ -6,7 +6,7 @@ local batteries = BATTERIES local tabline = wezterm.plugin.require("https://github.com/michaelbrusegard/tabline.wez") -tabline.setup({ +local tab_opts = { options = { icons_enabled = true, theme = "Catppuccin Mocha", @@ -97,11 +97,23 @@ tabline.setup({ }, tabline_z = { { "hostname", padding = { left = 0, right = 1 } }, - batteries.get_battery_icons, }, }, extensions = { "resurrect" }, -}) +} + +if batteries.get_battery_icons() ~= "" then + tab_opts.sections.tabline_z = { + { "hostname", padding = { left = 0, right = 1 } }, + batteries.get_battery_icons, + } +end + +if MYTABLINE ~= nil then + tab_opts = MYTABLINE +end + +tabline.setup(tab_opts) local function apply_tabline_config(conf) conf.use_fancy_tab_bar = false