tabline.wez

repository·main·Indexed 43 days ago

https://github.com/michaelbrusegard/tabline.wez

A versatile Lua-based tab-bar for the WezTerm terminal emulator, inspired by lualine.nvim. It provides a configurable interface for displaying window and tab components, including system metrics (CPU, RAM, battery), workspace information, and custom Lua components. Supports themes, Nerd Font icons, and extensions that trigger based on events.

Tokens
2.6K
Snippets
9
Records
11
Agent score
6%

What's inside tabline.wez

  1. Configure tabline.wez in wezterm.lua

    main

    To use tabline.wez, you must call tabline.setup() with a configuration table. The configuration is divided into options (global settings), sections (defining what components appear in which part of the bar), and extensions.

    Important Setup Step: After calling tabline.setup(), you must call tabline.apply_to_config(config) passing your WezTerm config object. This applies necessary WezTerm settings (like enabling the retro tab-bar) required for the plugin to function. If you have already manually configured these in wezterm.lua, you can skip this call.

    tabline.setup({
      options = {
        icons_enabled = true,
        theme = 'Catppuccin Mocha',
        tabs_enabled = true,
        -- ... other options
      },
      sections = {
        tabline_a = { 'mode' },
        tab_active = { 'index', 'cwd' },
        -- ... other sections
      },
    })
    
    tabline.apply_to_config(config)
  2. Install tabline.wez via WezTerm Plugin API

    main

    To use tabline.wez, load it into your wezterm.lua configuration using the wezterm.plugin.require function.

    Note: If you want to display icons in your tab-bar, you must use a patched font (like a Nerd Font) that supports them.

    local tabline = wezterm.plugin.require("https://github.com/michaelbrusegard/tabline.wez")
  3. Customize tabline themes and colors

    main

    Tabline supports various themes. You can set a theme by name (e.g., 'GruvboxDark') or use the WezTerm config colors object (config.colors).

    To modify specific colors, use the theme_overrides option within options. Overrides can be applied per keytable (mode) or for general tab colors. Note that keytables must end with _mode (e.g., normal_mode, copy_mode).

    Available Override Scopes:

    • {mode_name}_mode: Overrides colors for sections a, b, and c for a specific mode.
    • tab: Overrides active, inactive, and inactive_hover tab colors.

    You can also change the theme dynamically after setup using tabline.set_theme().

    -- Apply theme with specific overrides
    tabline.setup({
      options = {
        theme = 'Catppuccin Mocha',
        theme_overrides = {
          normal_mode = {
            c = { bg = '#112233' },
          },
          tab = {
            active = { fg = '#89b4fa', bg = '#313244' },
          }
        }
      }
    })
    
    -- Change theme dynamically
    tabline.set_theme('GruvboxDark')
  4. Configure tabline separators

    main

    Tabline uses three types of separators that can be customized using Nerd Font icons or strings. Setting them to an empty string '' disables them.

    • section_separators: Separators between the main sections (a, b, c, tabs, x, y, z).
    • component_separators: Separators between individual components within a section.
    • tab_separators: Separators on the left and right sides of each tab.
    options = {
      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,
      },
    }
  5. Refresh the tabline manually

    main

    While tabline refreshes automatically based on WezTerm's status_update_interval, you can force a refresh using tabline.refresh(window, tab).

    • Passing nil for window will not refresh the window-based sections.
    • Passing nil for tab will not refresh the tab-based sections.

    Warning: Do not call tabline.refresh inside component functions, as this can cause infinite loops or undesirable behavior during the refresh cycle.

    tabline.refresh(window, tab)
  6. Create custom tabline components

    main

    You can create custom components using several methods:

    1. Lua Functions: Pass a function that returns a string.
      • Tabline components receive (Window, Pane) as arguments.
      • Tab components receive (TabInformation, PaneInformation) as arguments.
    2. Text Strings: Any string is automatically wrapped in a Text FormatItem.
    3. WezTerm FormatItems: Pass a table of WezTerm format items (e.g., Attribute, Foreground, Background).
    4. Lua Expressions: Use oneliners, global variables, or require statements.
    -- 1. Lua Function
    local function hello() return 'Hello World' end
    sections = { tabline_a = { hello } }
    
    -- 2. Text String
    sections = { tabline_a = { 'Hello World' } }
    
    -- 3. WezTerm FormatItems
    sections = {
      tabline_c = {
        { Attribute = { Underline = 'Single' } },
        { Foreground = { AnsiColor = 'Fuchsia' } },
        'Hello World',
      }
    }
    
    -- 4. Lua Expression
    sections = { tabline_c = { os.date('%a'), require('util').status() } }
  7. Create custom tabline extensions

    main

    Extensions allow you to change the tabline appearance based on events from other plugins. An extension is defined as a table containing:

    • name: A unique string.
    • events: A table defining show and hide events (can be a single string or a table of strings).
    • delay (number): Seconds to wait before hiding (default 5).
    • callback (function): Called when the show event triggers.
    • sections: The sections to display when shown.
    • colors: Overrides for the extension's section colors.

    When a show event is triggered, the defined sections are displayed. If hide is not provided, sections hide after the delay.

    local my_extension = {
      'my_extension_name',
      events = {
        show = 'my_plugin.show',
        hide = 'my_plugin.hide',
        delay = 3,
        callback = function(window) wezterm.log_info('Extension shown') end
      },
      sections = { tabline_a = { 'mode' } },
      colors = { a = { fg = '#181825', bg = '#f38ba8' } }
    }
    
    tabline.setup({ extensions = { my_extension } })
  8. Configure component-specific options

    main

    Components can have local options that override global defaults.

    General Component Options

    Available for all components:

    • icons_enabled (bool): Enables/disables icons for this component.
    • icons_only (bool): Only shows the icon if the component has one.
    • icon (string|table): The icon to display. If a table, it can include align and color.
    • cond (function): A condition function; component only loads if it returns true.
    • padding (number|table): Padding for left/right. e.g., padding = { left = 0, right = 1 }.
    • fmt (function): A formatter function receiving (string, Window/TabInformation).

    Specific Component Examples

    • datetime: style (format string), hour_to_icon (table mapping hours to icons).
    • cwd / parent: max_length (integer).
    • index: zero_indexed (bool).
    • process: process_to_icon (table mapping process names to icons).
    • cpu / ram: throttle (seconds), use_pwsh (bool).
    • battery: battery_to_icon (table mapping levels to icons).
    • domain: domain_to_icon (table mapping domains to icons).
    • output: icon_no_output (icon to show when no unseen output exists).
  9. Use available tabline components

    main

    Components are assigned to sections in the sections table. They are categorized by the objects they have access to.

    Window Components

    (Available for tabline_a through tabline_z)

    • mode: Current keytable (mode)
    • battery: Battery percentage
    • cpu: CPU percentage
    • datetime: Current date and time
    • domain: Current domain
    • hostname: Hostname of the machine
    • ram: RAM used in GB
    • window: Window title
    • workspace: Active WezTerm workspace

    Tab Components

    (Available for tab_active and tab_inactive)

    • tab: Tab title
    • cwd: Current working directory
    • output: Indicator if tab has unseen output
    • parent: Parent directory
    • process: Process name
    • index: Tab index
    • zoomed: Indicator if tab has zoomed pane
  10. Calculate tab index for tabline entries

    main

    The update function provides a way to calculate the display index for a tab entry. It supports an option zero_indexed to determine whether the index should be 0-based or 1-based.

    • If opts.zero_indexed is true, it returns tab.tab_index.
    • If opts.zero_indexed is false (default), it returns tab.tab_index + 1.
    -- Example of how the update logic behaves:
    -- Assuming tab.tab_index = 0
    
    -- With zero_indexed = true
    -- Result: 0
    
    -- With zero_indexed = false (default)
    -- Result: 1