SkillAgentSearch skills...

I3blocks

The hacker-friendly status_command for Sway and i3

Install / Use

/learn @vivien/I3blocks
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

:progname: i3blocks :toc:

= {progname}

The hacker-friendly status_command for Sway and i3

{progname} is a feed generator for text based status bars. It executes your command lines and generates a status line from their output. Commands are scheduled at configured time intervals, upon signal reception or on clicks.

The generated line is meant to be displayed by the link:https://i3wm.org[i3] window manager through its i3bar component, as an alternative to i3status. This program naturally works out of the box with the link:https://swaywm.org[sway] Wayland compositor since it is a drop-in replacement for i3.

{progname} is meant to be highly flexible but intuitive. No library package is required, just output what your status bar expects, from your favorite programming language and your preferred format.

== Example

[source,ini]

[click] full_text=Click me! command=echo "Got clicked with button $button" color=#F79494

Guess the weather hourly

[weather] command=curl -Ss 'https://wttr.in?0&T&Q' | cut -c 16- | head -2 | xargs echo interval=3600 color=#A4C2F4

Query my default IP address only on startup

[ip] command=hostname -i | awk '{ print "IP:" $1 }' interval=once color=#91E78B

Update time every 5 seconds

[time] command=date +%T interval=5

== Installation

{progname} is already packaged for:

  • Archlinux: link:https://www.archlinux.org/packages/community/x86_64/i3blocks[i3blocks] in the community repository and link:https://aur.archlinux.org/packages/i3blocks-git[i3blocks-git] in the AUR
  • Gentoo: link:https://packages.gentoo.org/packages/x11-misc/i3blocks[x11-misc/i3blocks]
  • Debian: link:https://packages.debian.org/i3blocks[i3blocks]
  • Ubuntu: link:http://packages.ubuntu.com/i3blocks[i3blocks]
  • Fedora (COPR): link:https://copr.fedorainfracloud.org/coprs/wyvie/i3blocks[i3blocks]
  • Void Linux: link:https://github.com/void-linux/void-packages/tree/master/srcpkgs/i3blocks[i3blocks]

Or can be installed from source with:

[source]

git clone https://github.com/vivien/i3blocks cd i3blocks ./autogen.sh ./configure make make install

== Getting started

In your i3 configuration file, define {progname} as the link:https://i3wm.org/docs/userguide.html#status_command[status line command] of a new bar block:

[source]

bar { status_command i3blocks }

IMPORTANT: The project's repository does not include default scripts anymore.

For the lazy, you can start from link:https://github.com/vivien/i3blocks-contrib[our collection of scripts]:

[source]

git clone https://github.com/vivien/i3blocks-contrib ~/.config/i3blocks cd !$ cp config.example config

For the picky, you can start a configuration file in one of the following preferred paths:

  • $XDG_CONFIG_HOME/i3blocks/config (or ~/.config/i3blocks/config);
  • ~/.i3blocks.conf;
  • $XDG_CONFIG_DIRS/i3blocks/config (or /etc/xdg/i3blocks/config);
  • /etc/i3blocks.conf;
  • or any other path that you will specify using the -c option.

NOTE: By default /etc is prefixed by /usr/local when you installed from source.

Use the example above or dig in the configuration details below.

Now restart i3 with i3-msg restart to apply your changes.

== Blocks

The configuration file uses a simplified INI file format:

[source,ini]

Properties not preceded by a section are considered global

and merged into every section declarations.

foo=bar

[block1] baz=qux

This is a comment

[block2] quux= quuz

In this example, block2 contains a foo property equal to "bar" and a quux property equal to " quuz" (including the leading space). Everything after the equal sign will be part of the value, thus inline comments won't be stripped out.

At runtime, these properties are simply variables, that are passed along to the status bar program when printing is necessary. However on startup, {progname} checks some optional properties to eventually setup the scheduling of a command.

If a block specifies a command, then all of its properties are passed as environment variables at execution, which means that the foo=bar property will be available from a shell script with $foo. The output of the command is used to update the values of these variables. The values are reset to default (as defined in the configuration file) before the update, so that blocks get a consistent behavior at each execution.

NOTE: Each line from a block output must be terminated with a newline.

== i3bar properties

In order to use {progname} with i3, its status bar command i3bar expects specific keys. To know how to customize the blocks of your status line, you must refer to the link:https://i3wm.org/docs/i3bar-protocol.html#_blocks_in_detail[i3bar protocol].

NOTE: full_text is the only mandatory key, the block will be skipped if this key is absent or empty.

Unless overriden, the section name of the block defines the name key.

Below are examples of static blocks interacting with i3bar.

[source,ini]

[simple] full_text=This is a looong white on red text short_text=Short white on red text background=#FF0000 color=#FFFFFF

Block with a fixed width

[aligned] full_text=Here. min_width=100 align=center

Fancy text with multiple colors and shapes

[funky] full_text=<span foreground="red" size="x-large">Roses</span> and <i><span color="#EE37B8">violets</span></i>! markup=pango

== {progname} properties

These are some special properties checked by {progname} on startup. These will be considered as simple variables at runtime.

=== command

The optional command property specifies a command line to be executed with sh -c. The command can be relative to the configuration file where it is defined. If the command outputs some text, it is used to update the block.

An exit code of 0 means success. A special exit code of 33 will set the urgent i3bar key to true. Any other exit code will raise an error.

[source,ini]

[pacman] full_text=c · command=echo "· ${full_text~~}" color=#FFFF00

=== interval

The optional interval property specifies when the command must be scheduled.

A positive value represents the number of seconds to wait between exectutions.

[source,ini]

Print seconds since 1970-01-01

[epoch] command=date +%s interval=1

A value of 0 (or undefined) means the command is not timed whatsoever and will not be executed on startup. This is useful to trigger the command only on user input (e.g. signal or click), not before.

[source,ini]

Restart i3 on click

[restart] full_text=Restart command=i3-msg -q restart #interval=0

The interval value once (or -1) will schedule the command only on startup. This tells {progname} not to schedule the command again on a time basis. But events such as signals and clicks will execute the command again of course.

[source,ini]

Fetch the public IP address only on startup

[public-ip] command=wget -qO - icanhazip.com interval=once

The interval value repeat (or -2) will respawn the command as soon as it terminates. This is convenient for blocking programs which exit as soon as the awaited event arises.

NOTE: clicks are not supported with this value, since such commands are unlikely to expect data on their standard input.

[source,ini]

Print the last command entered in Bash

[history] command=inotifywait -qq -e close_write ~/.bash_history; tail -1 ~/.bash_history interval=repeat

The interval value persist (or -3) expects the command to be an infinite loop. Each line of the output will trigger an update of the block.

[source,ini]

[window] command=xtitle -s interval=persist

=== signal

Blocks can be scheduled upon reception of a real-time signal (think prioritized and queueable). The range of available signal numbers is 1 to N, where SIGRTMIN+N = SIGRTMAX. (Note: there are 31 real-time signals in Linux.)

[source,ini]

[caps-lock] command=xset -q | grep Caps | awk '{ print $2, $3, $4 }' interval=once signal=10

This example block above will be scheduled once {progname} handles the SIGRTMIN+10 signal. This can be sent directly from an i3 binding on Caps Lock release with the following configuration:

[source]

bindsym --release Caps_Lock exec pkill -SIGRTMIN+10 i3blocks

=== format

There are several formats supported to specify which variables {progname} must update. Some favor simplicity over flexibility but thus can be limited.

When undefined, a raw format is assumed. Each line of the output corresponds to an i3bar key, in the order of definition found in the link:https://i3wm.org/docs/i3bar-protocol.html#_blocks_in_detail[i3bar protocol]:

  • the 1st line updates the full_text;
  • the 2nd line updates the short_text;
  • the 3rd line updates the color;
  • the 4th line updates the background.

Excess lines are considered an error. Below is an example of a simple battery script.

.battery.sh [source,sh]

#!/bin/bash

BAT=$(acpi -b | grep -E -o '[0-9][0-9]?%')

Full and short texts

echo "Battery: $BAT" echo "BAT: $BAT"

Set urgent flag below 5% or use orange below 20%

[ ${BAT%?} -le 5 ] && exit 33 [ ${BAT%?} -le 20 ] && echo "#FF8000"

exit 0

[source,ini]

[battery] command=battery.sh interval=10

The json format can update any variable.

[source,ini]

[counter] _count=0 command=printf '{"full_text":"Counter: %s", "_count":%d}\n' $_count $((_count + 1)) format=json interval=1

== Click

When you click on a block, data such as the button number and coordinates are merged into the block variables.

NOTE: name and instance are the two keys used by i3bar to identify a block.

The data sent on click is detailed in the link:https://i3wm.org/docs/i3bar-protocol.html#_click_events[i3bar protocol].

If the block command isn't already spawned, it is executed again.

[source,ini]

Print click data

[clickme] align=center full_text=Click me! min_width=Button=? x=? y=? command=echo "Button=$button x=$x y=$y"

If the value of the block's interval

View on GitHub
GitHub Stars2.4k
CategoryDevelopment
Updated2d ago
Forks184

Languages

C

Security Score

100/100

Audited on Mar 27, 2026

No findings