Home

Awesome

wez-status-generator

<img src="https://raw.githubusercontent.com/sei40kr/wez-status-generator/main/img/screenshot.png" width="960" height="640" alt="screenshot">

Breaking changes

Installation

Clone this repository to your $XDG_CONFIG_HOME/wezterm:

git clone https://github.com/sei40kr/wez-status-generator.git $XDG_CONFIG_HOME/wezterm

Usage

-- Recommended configuration:
config.use_fancy_tab_bar = false

wezterm.on("update-status", function(window, pane)
    local status_generator = require("wez-status-generator.plugin")
    local status = status_generator.generate_left_status({
        sections = {
            {
                components = {
                    function() return window:mux_window():get_workspace() end,
                },
                foreground = "#15161e",
                background = "#7aa2f7",
            },
            {
                components = {
                    function() return os.getenv("USER") end,
                },
                foreground = "#7aa2f7",
                background = "#3b4261",
            },
            {
                components = {
                    function()
                        local tab_id = window:mux_window():active_tab():tab_id()
                        local pane_id = pane:pane_id()

                        return tab_id .. ":" .. pane_id
                    end,
                },
                foreground = "#a9b1d6",
                background = "#16161e",
            },
        },
        separator = wezterm.nerdfonts.pl_left_hard_divider,
        hide_empty_sections = true,
    })

    window:set_left_status(status)
end)
-- Recommended configuration:
config.use_fancy_tab_bar = false

wezterm.on("update-status", function(window, pane)
    local status_generator = require("wez-status-generator.plugin")
    local status = status_generator.generate_right_status({
        sections = {
            {
                components = {
                    function() return wezterm.strftime("%H:%M:%S") end,
                },
                foreground = "#a9b1d6",
                background = "#16161e",
            },
            {
                components = {
                    function() return wezterm.strftime("%d-%b-%y") end,
                },
                foreground = "#7aa2f7",
                background = "#3b4261",
            },
            {
                components = {
                    function() return wezterm.hostname() end,
                },
                foreground = "#15161e",
                background = "#7aa2f7",
            },
        },
        separator = wezterm.nerdfonts.pl_right_hard_divider,
        hide_empty_sections = true,
    })

    window:set_right_status(status)
end)

API References

generate_left_status, generate_right_status

Generate a status for the left or right side of the window. Expected to be called from the update-status callback.

Arguments

NameTypeDefaultDescription
optstableRequiredOptions for the status
opts.sections[]tableRequiredSection of the status
opts.sections[].components[]fun(): string?RequiredComponent of the section. Specify a function that returns a string to render.
opts.sections[].separatorstring?" | "Separator between components of the section
opts.sections[].paddingnumber?1Padding inside the section
opts.sections[].foregroundstringRequiredForeground color of the section
opts.sections[].backgroundstringRequiredBackground color of the section
opts.separatorstringLeft: wezterm.nerdfonts.pl_left_hard_divider<br />Right: wezterm.nerdfonts.pl_right_hard_dividerSeparator between the sections.
opts.hide_empty_sectionsbooleantrueWhether to hide the section if all components are empty

Returns

A string to be set as the status.

Tips

Insert spaces between the left status and the tab bar

-- Change the number of spaces as you like
window:set_left_status(status .. (" "):rep(2))

The workspace names set by wez-per-project-workspace are too long to display

wez-per-project-workspace sets the workspace names to the full path of the project directory and it's too long to display.

You can truncate a workspace name to display the last directory name only.

local status = status_generator.generate_left_status({
    sections = {
        {
            components = {
                function()
                    return window:mux_window():get_workspace():gsub(".*/", "")
                end,
            },
        },
    },
})

Use wezterm.format to set the attributes of a component

You cannot simply set the attributes of a component with wezterm.format because it resets current attributes all.

As a workaround, you can put the foreground/background colors of the section together.

local status = status_generator.generate_left_status({
    sections = {
        {
            components = {
                function()
                    return wezterm.format({
                        { Attribute = { Intensity = "Bold" } },

                        -- Put the foreground/background colors of the section together
                        { Foreground = { Color = "#15161e" } },
                        { Background = { Color = "#7aa2f7" } },

                        { Text = window:mux_window():get_workspace() },
                    })
                end,
            },
            foreground = "#15161e",
            background = "#7aa2f7",
        },
    },
})