Top Related Projects
A fast and easy-to-use status bar
Light-weight system monitor for X, Wayland (sort of), and other things, too
A tiling window manager for macOS based on binary space partitioning
Rofi: A window switcher, application launcher and dmenu replacement
ElKowars wacky widgets
Quick Overview
i3blocks is a flexible status bar for i3 window manager, written in C. It allows users to define custom blocks for displaying system information, executing scripts, and showing real-time updates in a highly configurable manner.
Pros
- Highly customizable with support for user-defined scripts and blocks
- Lightweight and efficient, with minimal resource usage
- Compatible with i3 window manager and follows its design philosophy
- Active community and regular updates
Cons
- Limited to i3 window manager, not usable with other desktop environments
- Requires some programming knowledge for advanced customization
- Documentation could be more comprehensive for beginners
- Some users report occasional stability issues with certain blocks
Code Examples
- Basic block configuration in i3blocks.conf:
[time]
command=date '+%Y-%m-%d %H:%M:%S'
interval=1
[battery]
command=acpi -b | awk '{print $4}' | sed 's/,//'
interval=10
This example shows two blocks: one for displaying the current time, updating every second, and another for showing battery status, updating every 10 seconds.
- Custom script block:
#!/bin/bash
# Save as ~/.config/i3blocks/scripts/custom_block.sh
echo "Custom Info: $(whoami)@$(hostname)"
echo "#FF0000" # Sets the text color to red
This custom script displays the current user and hostname with red text color.
- Using the custom script in i3blocks.conf:
[custom]
command=$HOME/.config/i3blocks/scripts/custom_block.sh
interval=60
This configuration adds the custom script as a block, updating every 60 seconds.
Getting Started
-
Install i3blocks:
sudo apt-get install i3blocks
-
Create or edit ~/.config/i3/config and add:
bar { status_command i3blocks }
-
Create ~/.config/i3blocks/config and add block configurations:
[time] command=date '+%H:%M:%S' interval=1 [memory] command=free -h | awk '/^Mem:/ {print $3 "/" $2}' interval=30
-
Restart i3 or reload the configuration to see the new status bar.
Competitor Comparisons
A fast and easy-to-use status bar
Pros of polybar
- More customizable and feature-rich, offering a wider range of modules and styling options
- Better documentation and community support, with extensive wiki and user configurations available
- Cross-compatible with multiple window managers, not limited to i3
Cons of polybar
- Steeper learning curve due to more complex configuration
- Higher resource usage, especially with many modules enabled
- Requires external dependencies for some features
Code comparison
i3blocks configuration:
[time]
command=date '+%Y-%m-%d %H:%M:%S'
interval=1
[battery]
command=acpi -b | awk '{print $4}' | sed 's/,//'
interval=10
polybar configuration:
[module/date]
type = internal/date
interval = 1
date = %Y-%m-%d
time = %H:%M:%S
format = <label>
label = %date% %time%
[module/battery]
type = internal/battery
battery = BAT0
adapter = AC
full-at = 98
format-charging = <label-charging>
format-discharging = <label-discharging>
i3blocks offers a simpler configuration syntax, while polybar provides more detailed control over module appearance and behavior. polybar's built-in modules often require less external scripting compared to i3blocks.
Light-weight system monitor for X, Wayland (sort of), and other things, too
Pros of Conky
- More versatile and customizable, supporting a wide range of system information displays
- Can be used as a standalone desktop widget, not limited to status bars
- Extensive scripting capabilities with Lua integration
Cons of Conky
- Steeper learning curve due to its complexity and configuration options
- Higher resource usage, especially for complex setups
- Less focused on status bar integration compared to i3blocks
Code Comparison
i3blocks configuration:
[cpu_usage]
command=$SCRIPT_DIR/cpu_usage
interval=10
LABEL=CPU
#min_width=CPU: 100.00%
#T_WARN=50
#T_CRIT=80
#DECIMALS=2
Conky configuration:
conky.config = {
cpu_avg_samples = 2,
net_avg_samples = 2,
update_interval = 1.0,
double_buffer = true,
no_buffers = true,
text_buffer_size = 2048,
}
conky.text = [[
${cpu cpu0}% ${cpubar 4}
]]
Both projects aim to display system information, but Conky offers more flexibility and standalone functionality, while i3blocks is more focused on integration with the i3 window manager's status bar. i3blocks has a simpler configuration syntax, while Conky uses Lua for more advanced customization.
A tiling window manager for macOS based on binary space partitioning
Pros of yabai
- Designed specifically for macOS, offering native integration and optimization
- Provides advanced window management features like window gaps and padding
- Supports scripting and custom rules for fine-grained control
Cons of yabai
- Limited to macOS, not cross-platform like i3blocks
- Steeper learning curve due to more complex configuration options
- Requires disabling System Integrity Protection (SIP) for full functionality
Code Comparison
i3blocks configuration example:
[time]
command=date '+%Y-%m-%d %H:%M:%S'
interval=1
[battery]
command=acpi -b | awk '{print $4}'
interval=10
yabai configuration example:
yabai -m config layout bsp
yabai -m config top_padding 20
yabai -m config window_gap 10
yabai -m rule --add app="^System Preferences$" manage=off
While i3blocks focuses on status bar configuration with simple blocks, yabai's configuration revolves around window management rules and layout settings. i3blocks is more straightforward for basic system information display, while yabai offers powerful window control but requires more detailed setup.
Rofi: A window switcher, application launcher and dmenu replacement
Pros of rofi
- More versatile: functions as an application launcher, window switcher, and dmenu replacement
- Highly customizable appearance with theming support
- Extensible through custom modes and scripts
Cons of rofi
- Steeper learning curve due to more complex configuration options
- Larger resource footprint compared to i3blocks' lightweight nature
- May be overkill for users only needing a simple status bar
Code comparison
rofi configuration example:
rofi.theme: /path/to/theme.rasi
rofi.modi: window,run,ssh
rofi.width: 50
rofi.lines: 15
rofi.columns: 2
i3blocks configuration example:
[cpu_usage]
command=$SCRIPT_DIR/cpu_usage
interval=10
label=CPU
[memory]
command=$SCRIPT_DIR/memory
interval=30
label=MEM
Key differences
- rofi is a standalone application with broader functionality
- i3blocks is specifically designed for use with the i3 window manager
- rofi focuses on user interaction, while i3blocks is primarily for displaying system information
- i3blocks uses a simpler configuration format, making it easier to set up for basic status bar needs
- rofi offers more advanced features like fuzzy matching and custom scripting capabilities
ElKowars wacky widgets
Pros of eww
- More flexible and customizable, allowing for complex widgets and layouts
- Uses Yuck, a declarative language, for easier configuration
- Supports a wider range of desktop environments and window managers
Cons of eww
- Steeper learning curve due to its more complex configuration system
- Requires more system resources compared to i3blocks' lightweight nature
- Less integrated with i3, potentially requiring additional setup for i3 users
Code Comparison
i3blocks configuration:
[time]
command=date '+%Y-%m-%d %H:%M:%S'
interval=1
eww configuration (Yuck):
(defwidget time []
(box :class "time"
(label :text "${formattime(EWW_TIME, '%Y-%m-%d %H:%M:%S')}"))
)
Summary
eww offers greater flexibility and customization options, making it suitable for users who want to create complex and visually appealing status bars across various desktop environments. However, it comes with a steeper learning curve and higher resource usage. i3blocks, on the other hand, is more lightweight and tightly integrated with i3, making it a simpler choice for i3 users who prefer a straightforward configuration process.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
: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=Roses and violets! 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 is persist, then the data is written on the command standard input, one line per click. What gets written depends on the block's format. The raw format only gets the click button. The JSON format gets all block variables.
[source,ini]
[click-loop] full_text=Click me! command=while read button; do echo "Got click $button"; done interval=persist
[click-loop-json] full_text=Click me! command=ruby -r json -n -e '$_ = JSON.parse($)' -e '$["full_text"] = "Click %s at (%d,%d)" % $.slice("button", "x", "y").values' -e 'puts JSON.dump($)' -e 'STDOUT.flush' interval=persist format=json
== FAQ
Frequently Asked Questions and Troubleshooting.
[qanda] What is a blocklet?:: A blocklet is the configuration of a single block, part of the status line. There are plenty listed in the link:https://vivien.github.io/i3blocks/blocklets[blocklets page].
Can I use my own variables?::
Yes, any variable defined in the block is exported as is to the environment of its command.
The foo=bar
property can be accessed with $foo
from a shell script, ENV["foo"]
from Ruby, and so on.
+
The IEEE and The Open Group state that link:http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html["The name space of environment variable names containing lowercase letters is reserved for applications."].
i3bar suggests to prefix your own keys with an underscore (_
), but it might be more intuitive to use uppercase environment variables, so it is your call to define your own naming convention.
Why $foo
doesn't work from the configuration file?::
{progname} does not do string interpolation of any sort.
The definitions found in the configuration file are just raw strings, this means that bar=$baz
defines a bar variable equal to literally $baz
(a dollar sign followed by "baz").
+
String interpolation does work in the command property though, since it is interpreted by a shell which has access to the environment variables.
How can I simulate a button?:: This is pretty straightforward actually. Just make sure not to override the full_text, for example: + [source,ini]
[calc-button] full_text=Calculator command=gnome-calculator >/dev/null
Can a block start a GUI application?::
Sure.
And if you do not wish your command to block until the application is closed, ask i3 to start it for you with i3-msg -q exec myapp
.
Why Pango isn't working?:: The Pango markup requires a Pango font. Make sure you configured link:https://i3wm.org/docs/userguide.html#_font[i3bar] to use a Pango font. For example: + [source]
font pango:Inconsolata, Icons 12
Why is printf
not working?::
As of {progname} 1.5, each line from a block output are expected to be terminated with a newline, e.g. with printf "...\n"
from a shell script.
Why is the output from my persistent block not displayed?:: Make sure to flush stdout, for example: + [source,ini]
[ruby-loop] full_text=Click me command=ruby -p -e '$_.prepend("Got button ")' -e 'STDOUT.flush' interval=persist
Can I use a time interval below 1 second?:: No, the time unit for interval is the second. + But even though I wouldn't recommend it, you can still update faster than that with loops: + [source,ini]
[nano1] command=sleep .5; date +%N interval=repeat
[nano2] command=while sleep .5; do date +%N; done interval=persist
Can I change the block separator?:: Not with {progname} itself, separators are drawn by i3bar. You can change the separator_symbol in the link:https://i3wm.org/docs/userguide.html#_custom_separator_symbol[i3bar configuration]. + Alternatively, you can define static blocks as custom separators in your {progname} configuration. In the example below, we use the "\xe3\x80\x89" UTF-8 character: + [source,ini]
Define the custom separator in global properties for boilerplate
full_text=ã align=center color=#666666 separator=false separator_block_width=7
[time] instance=la TZ=America/Los_Angeles command=date +%T interval=5
[separator]
[time] instance=nc TZ=Pacific/Noumea command=date +%T interval=5
[separator]
[time] instance=mtl TZ=America/Montreal command=date +%T interval=5
== Debugging
The log level can be increased with the -v
option.
If your window manager (and thus this program) is run via systemd, you can inspect the program outputs with journalctl -t <identifier> -f
.
You may also use this in conjonction with running the program manually with systemd-cat -t <identifier> ./i3blocks
.
Alternatively you can redirect the standard output and error streams from the program invokation with:
[source]
bar { status_command 2>/tmp/i3blocks.err /path/to/i3blocks -vvv -c /path/to/config | tee /tmp/i3blocks.out }
And inspect the log with tail -f /tmp/i3blocks.err
.
See the link:{progname}.1{outfilesuffix}[manpage] for details about the command line options and {progname} usage.
== License
{progname} is Copyright (C) Vivien Didelot
See the file COPYING for information of licensing and distribution.
Top Related Projects
A fast and easy-to-use status bar
Light-weight system monitor for X, Wayland (sort of), and other things, too
A tiling window manager for macOS based on binary space partitioning
Rofi: A window switcher, application launcher and dmenu replacement
ElKowars wacky widgets
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot