i3status-rust icon indicating copy to clipboard operation
i3status-rust copied to clipboard

Configuration in `lua`

Open MaxVerevkin opened this issue 4 years ago • 2 comments

Using lua for configuration gives a lot of flexibility and control: conditional blocks, click handlers in lua, custom formatting in lua, dynamic themes/icons and a lot more. Here is an example of a lua config (it actually works):

-- Returns command's output
local function cmd(c)
    local proc = io.popen(c)
    local output = proc:read()
    proc:close()
    return output
end

-- Set icons and theme
config.icons = "material-nf"
config.theme = {
    name = "slick",
    overrides = {
        alternating_tint_bg = "#0C0C0C00",
        alternating_tint_fg = "#0C0C0C00",
    }
}

-- Simple, unconditional block (`block` function just appends to the `config.block` table)
block {
    block = "disk_space",
    info_type = "available",
    alert_unit = "GB",
    alert = 10.0,
    warning = 15.0,
    format = "$available"
}

-- As an example, add kbd layout block only if more than one layout is available
local layouts_cnt = cmd("swaymsg -t get_inputs | jq '.[].xkb_layout_names | length | select(. > 0)' | head -n1")
if (layouts_cnt ~= "1") 
then
    block {
        block = "sway_kbd",
        mappings = {
            ["English (Workman)"] = "EN",
            ["Russian"] = "RU"
        }
    }
end

-- It's possible to schedule functions. In this example "hello" is printed to stderr every second.
add_timer(1000, function()
    io.stderr:write("hello")
end)

MaxVerevkin avatar Nov 27 '21 14:11 MaxVerevkin

please keep this optional.

ghost avatar Mar 14 '23 05:03 ghost

@deepaknegilachu don't worry, TOML config isn't going anywhere.

MaxVerevkin avatar Mar 14 '23 10:03 MaxVerevkin