bar.wezterm

repository·main·Indexed 42 days ago

https://github.com/adriankarlen/bar.wezterm

A customizable tab bar configuration plugin for the WezTerm terminal emulator. It provides a status bar with modules for workspace, leader, zoom, pane, user, host, clock, cwd, SSH, and Spotify, with support for dynamic tab customization rules based on domain name or current working directory.

Tokens
2.3K
Snippets
5
Records
5
Agent score
4%

What's inside bar.wezterm

  1. Install bar.wezterm

    main

    To install bar.wezterm, import the repository using wezterm.plugin.require and call bar.apply_to_config(config).

    Important: You must call apply_to_config after your color_scheme has been set in your WezTerm configuration. This assumes you have already initialized your wezterm module and config object.

    local bar = wezterm.plugin.require("https://github.com/adriankarlen/bar.wezterm")
    bar.apply_to_config(config)
  2. Define dynamic tab customization rules

    main

    You can define rules within modules.tabs to override tab colors and icons based on the domain name or the current working directory (cwd). Rules are evaluated in the order they are listed, and matching rules override properties defined in previous rules.

    Supported matching methods for domain and cwd:

    • Exact Match: Provide a string (e.g., domain = "WSL:Ubuntu").
    • Pattern Match: Provide a table with a pattern key using Lua string patterns (e.g., domain = { pattern = "^SSH" }).
    • Predicate Function: Provide a function that returns a boolean (e.g., domain = function(name) return name:find "prod" ~= nil end).

    Note: cwd paths are compared with a trailing /.

    bar.apply_to_config(config, {
      modules = {
        tabs = {
          rules = {
            {
              -- check domain name; requires exact, case-sensitive matchs
              domain = "WSL:Ubuntu",
              -- you can override tab's color or icon
              active_tab_fg = 3,
              inactive_tab_fg = 3
            },
            {
              -- check domain name using pattern (see lua's string.match)
              domain = { pattern = "^SSH" },
              active_tab_fg = 1,
              inactive_tab_fg = 1,
              icon = wez.nerdfonts.md_ssh
            },
            {
              -- check domain name using a custom predicate
              domain = function(name) return name:find "prod" ~= nil end,
              active_tab_bg = "#eb6f92",
              inactive_tab_bg = "#eb6f92"
            },
            {
              -- check cwd, same syntax as with domain names; paths compare with a
              -- trailing "/", so this matches /home/pet-projects itself as well
              cwd = { pattern = "^/home/pet-projects/" },
              -- when cwd and domain are given at the same time, both should match
              domain = "local",
              active_tab_fg = 6,
              inactive_tab_fg = 6
            },
          },
        },
      },
    })
  3. Customize tab colors and ANSI settings

    main

    You can customize the foreground (_fg) and background (_bg) colors for tabs. Colors can be specified using either an ANSI color index (integer) or a hex color string (e.g., "#c6a0f6").

    Available tab color options:

    • active_tab_fg (Default: 4)
    • active_tab_bg (Default: "transparent")
    • inactive_tab_fg (Default: 6)
    • inactive_tab_bg (Default: "transparent")
    • new_tab_fg (Default: 2)
    • new_tab_bg (Default: "transparent")
    bar.apply_to_config(config, {
      modules = {
        tabs = {
          active_tab_fg = 1,
          active_tab_bg = 6,           -- ansi color index
          -- or use a hex color:
          -- active_tab_bg = "#c6a0f6",
        },
      },
    })
  4. Configure bar.wezterm modules

    main

    The apply_to_config function accepts an optional second parameter opts, which is a table used to override default settings. You can enable or disable specific modules (like spotify or ssh) by passing them in the modules table.

    Prerequisites for specific modules:

    • SSH: Detects SSH sessions and displays an indicator. It automatically hides the cwd module during SSH sessions to avoid incorrect directory displays.
    • Spotify: Requires spotify-tui to be installed on your system.
    -- example enable spotify module
    bar.apply_to_config(
      config,
      {
        modules = {
          spotify = {
            enabled = true,
          },
        },
      }
    )
  5. Default configuration schema

    main

    The following is the complete default configuration structure for bar.wezterm.

    Requirement: You must use a Nerd Font or have "Symbols Nerd Font" installed for the icons to render correctly.

    Note: ssh and spotify modules are disabled by default.

    local config = {
      position = "bottom",
      max_width = 32,
      padding = {
        left = 1,
        right = 1,
        tabs = {
          left = 0,
          right = 2,
        },
      },
      separator = {
        space = 1,
        left_icon = wez.nerdfonts.fa_long_arrow_right,
        right_icon = wez.nerdfonts.fa_long_arrow_left,
        field_icon = wez.nerdfonts.indent_line,
      },
      modules = {
        tabs = {
          active_tab_fg = 4,
          active_tab_bg = "transparent",
          inactive_tab_fg = 6,
          inactive_tab_bg = "transparent",
          new_tab_fg = 2,
          new_tab_bg = "transparent",
          rules = {},
        },
        workspace = {
          enabled = true,
          icon = wez.nerdfonts.cod_window,
          color = 8,
        },
        leader = {
          enabled = true,
          icon = wez.nerdfonts.oct_rocket,
          color = 2,
        },
        zoom = {
          enabled = false,
          icon = wez.nerdfonts.md_fullscreen,
          color = 4,
        },
        pane = {
          enabled = true,
          icon = wez.nerdfonts.cod_multiple_windows,
          color = 7,
        },
        username = {
          enabled = true,
          icon = wez.nerdfonts.fa_user,
          color = 6,
        },
        hostname = {
          enabled = true,
          icon = wez.nerdfonts.cod_server,
          color = 8,
        },
        clock = {
          enabled = true,
          icon = wez.nerdfonts.md_calendar_clock,
          format = "%H:%M",
          color = 5,
        },
        cwd = {
          enabled = true,
          icon = wez.nerdfonts.oct_file_directory,
          color = 7,
        },
        ssh = {
          enabled = false,
          icon = wez.nerdfonts.md_ssh,
          color = 5,
        },
        spotify = {
          enabled = false,
          icon = wez.nerdfonts.fa_spotify,
          color = 3,
          max_width = 64,
          throttle = 15,
        },
      },
    }