Blocks of i3blocks: stuff that rocks

Just sharing my current configuration of i3blocks because someone asked, down there in the Tiling WM community on G+ (seriously, I do use G+).  If you are reading this, you probably know what Linux, a (tiling) WM (specifically i3 but there are lots more) and i3blocks are. Otherwise, just ask or Google the hell out of it ;).

I am a bit lazy when it comes to “ricing” and I also have little spare time, so don’t expect anything fancy or perfectly consistent: it just works and doesn’t burn my eyes.

Since i3blocks was included in Debian repositories (end of 2014), I decided to give it a try to replace the more sober, but less flexible at the time, i3status. I have been experimenting quite a lot with blocklets (that is, each of the scripts that output information in the bar), although not all of them deserved a permanent place in my configuration.

After a bit of tinkering and refinement, I finally settled on a reasonable arrangement, following a simple principle: show the meaningful bits of information without wasting space, in a format that conveys the proper (from my point of view) level of detail.

i3blocks 1-0-1

Boiling down the instructions in the i3blocks wiki, you’ll need 1) a bunch of scripts that 2) will be invoked in the order you’ll list them in i3blocks configuration file, that 3) in turn will be launched in the i3 config file.

Scripts can use any language you like (i3blocks invokes them and only captures their output) as long as they print out, in order, the “short length” output, the “full length” output and (optionally) the #RRGGBB colour assigned to text. Something as simple as

#!/bin/bash
# Super fancy script - YAY! I'm a h4x0r!
echo "$USER"
echo "Hello I am $USER"
echo "#E5E5E5"
exit 0

would be a perfectly valid blocklet (comment is optional 😉 ). Colour could also be assigned within the blocklet definition in the configuration file, in which you basically provide the script path and some additional information.

[fancyscript]
command=$HOME/scripts/fancyscript.sh
color=#E5E5E5
interval=30

Even easier than that, in the command row you can even have a simple command providing the “content”: my first iteration of the volume blocklet (see below) was just

command=amixer get Master | egrep -o -m1 "[0-9]{1,3}%"

I won’t go into much detail for each of my blocklets and related chunk of configuration file, as the wiki explains all the available options. However, please feel free to ask in the comments in case of any doubt: I’ll be happy to help if I can.

My blocks, my rules

In my current configuration I run two instances of i3bar + i3blocks, placed on the bottom edge of each screen (a 23″ FullHD TV in front of me and the 15″ laptop one on the right).

The excerpt from i3 config file shows how each instance is launched with its own configuration file:

bar {
    position bottom
    output LVDS-0
    status_command i3blocks -c $HOME/.config/i3/i3blocks_dual_laptop.conf
    ...
}

bar {
    position bottom
    output VGA-0
    tray_output none
    status_command i3blocks -c $HOME/.config/i3/i3blocks_dual_tv.conf
    ...
}

On the larger screen I have grouped blocks I might want to look at more often (and with higher rate of variation): status of media player (MOC), used RAM/swap, CPU load and temperature, nVidia GPU used RAM and temperature and finally free space on partitions.

On the small screen I have all the stuff I just glance every now and then: audio volume, date and time, network up-/download activity. The bar on this screen also shows the system tray.

I mostly used the default scripts at the beginning, then started to tweak them here and there to fit the desired appearance and output: scripts are usually just a few lines long, performing simple tasks with little system load (there’s for sure a lot of room for improvements).

Terminus all over the places and Symbola font (that recently replaced FontAwesome) for “icons” and weird symbols: some of those special Unicode chars won’t be rendered correctly in browser, so please have a look at the relevant picture of each block for the actual appearance.

Additional scripts can be also found in the i3blocks-contrib repository on Github: they provide both interesting features to add to your setup and a good starting point for your own blocklets. Check’em out.

Volume / Date / Network activity

i3blocks_volume_date_network

Volume, date, network (download/upload) activity

I’ll start from blocklets on my laptop screen to illustrate the “guideline” I try to follow. Most of the times you’ll have the volume indicator of choice showing the level in percentage: I thought it was not worth to waste up to 4 characters (“100%”) + glyph (some can take more than a single space) to know the exact volume level. Instead, I just want to be sure I don’t blow my ears when I play music. I’ll then adjust the audio level to what I fell comfortable for the moment, so again I don’t need to have a number for that. A simple 9-level gauge (the characters “_▁▂▃▄▅▆▇█”) is more than enough for the purpose.

On the other hand, I like to have an extended date format, even including day name and week number (and related glyphs): for this kind of information I preferred an higher level of detail.

Finally, the blue and white arrows and dots on the right, near the system tray, just change colour when there is download/upload network activity. This blocklet (actually, two instances of the same script, one for download, one for upload) used to be the default script showing network speed in kB/s: after a while I realized that it was completely useless to show those ever changing numbers: any network-intensive activity can usually be monitored directly through the same application that is generating network traffic (browser, p2p client, wget, …). So I modified the script to just output (remember: short text, long text, colour) a grey dot when there’s no activity during the polling interval (1 second), a coloured dot otherwise. Next step will (might) be to remove the dots and only have arrows changing colour (the upward and downward arrows are currently static labels).

Summing up: I don’t want to be “minimal” at all costs, I just want to show what I really need to know about my system. From the appearance standpoint, I am using enough colours to differentiate blocklets and highlight important variations without being distracted. And now let’s move on to the other screen!

MOC (Music On Console media player)

hgjgjhgj

MOC Playing – Paused – Not running

This one was made from scratch, with very little effort. When invoked with the “-i” option, mocp outputs information on the current track.

Output is then piped through sed to replace status descriptions with mediaplayer-ish symbols:

#!/bin/bash
# mocp playing song script
maxlen=${BLOCK_INSTANCE:-30}
full_text="MOC not running!"
short_text="$full_text"
color="#505050"
if [[ ! -z $(pidof mocp) ]]
then
full_text="$(mocp -i -Q "%state%song (%artist)" | tail -n 1 | sed -e 's/PLAY//' -e 's/PAUSE//' -e 's/STOP//')"
short_text="${full_text:0:$maxlen}"
color="#90A959"
fi
echo "$short_text"
echo "$full_text"
echo "$color"
case $BLOCK_BUTTON in
1) mocp -r ;; # left click = previous song
2) mocp -G ;; # middle click = toggle pause - play
3) mocp -f ;; # right click = next song
esac
exit 0

The big thing in this tiny script (because “it’s bigger on the inside”) is the $BLOCK_INSTANCE variable, that can be assigned in the configuration file and “passed” to the actual script.  The relevant part of configuration file for this blocklet declares a value for parameter “instance” that will then become the $BLOCK_INSTANCE value used in the script.

[MOC]
command=$HOME/.config/i3/i3b_script/mocp.sh
instance=40
...

The other big thing is the clickable area of the blocklet, matched with commands for media player control. The $BLOCK_BUTTON value is captured by i3blocks and passed to the script to execute the assigned actions.

Clickable areas are a feature i3blocks had since the earliest versions I dared to try. Alternatively, you could make a clickable “static” block (not displaying variable content, contrarily to a media player) actually simulating a “button” to launch applications and commands. In a past configuration, for example, I had a “button” launching a zenity-based dialog window with logout/suspend/power off options listed.

Memory

i3blocks_ram_swap

RAM and swap space

This is just the default script provided by the package, having awk performing some magic on /proc/meminfo. I run one instance for RAM and one for swap without a separator (the yellow backslash thingy) to make them appear as a single block (“separator=false” in the RAM block definition).

Excerpt from i3blocks config:

[memory]
#label=
command=$HOME/.config/i3/i3b_script/memory.sh
separator=false
color=#75B5AA
interval=30
min_width=M 4.0G

[swap]
#label=SWAP
instance=swap
command=$HOME/.config/i3/i3b_script/memory.sh swap
interval=30
color=#75B5AA
min_width=Sw 4.0G

CPU load and temperature

i3blocks_cpu_load_temp

CPU load and temperature

Here I use mpstat to read CPU load and again some awk wizardry to evaluate load percentage and set a different text colour (green > orange > red) when load exceeds a given threshold. Temperature, instead, is read by sensors and, again, processed to be assigned the proper text colour.

Wait! No “big thing” here? Sure! See the “[cpu-label]” code block below? It’s… uhm… well… a label: a simple fixed text, with no script associated. This way I’ll always have a bright symbol, clearly standing out from the darker background and not changing its colour according to script output.

[cpu-label]
full_text=[] # Note to readers: due to some troubles with the wacky HTML of WordPress, symbol was replaced by "[]"
color=#ff00ff

[cpu]
command=$HOME/.config/i3/i3b_script/simple_cpu_usage.sh
interval=5
align=right
min_width=X0.0%

GPU (nVidia) monitor

i3blocks_nvidia

nVidia GPU monitor

I am very careful about hardware temperature, much more than I am about disk space or memory. Also, I was just curious what the dedicated GPU was doing all the time down there, since my oldish CPU has no integrated graphics to share the work. One more important reason to monitor temperatures is to understand if the cooling system is working as intended: vents clogged by dust or, even, thermal compound dried out and ineffective cause quick temperature raises when CPU/GPU is under load that user needs to be aware of.

I query several parameters through the nvidia-smi command line tool, provided by the packaged binary drivers, and pipe output to awk (again, that lovely little treasure!) only to embellish it with icons and whatnot (not shown here):

nvidia-smi --format=nounits,csv,noheader --query-gpu=memory.used,pstate,temperature.gpu

Different video cards may expose different parameters, so check out your model’s documentation (or just try and see if you succeed!).

Disk space

i3blocks_storage

Storage monitor

There’s pretty little to say about this blocklet: it’s one of the default scripts you get at install and it basically runs df on partitions of your choice. My nerdy touch: I run the three instances (for /, /home and a data partition on a secondary drive) at intervals defined by prime numbers (29, 31 and 37 seconds). In addition to having reasonable timing around 30s for each (you don’t need to have more frequent updates, do you?), I try to minimize the times scripts are run at the same time: for example the first two instances will be run at the same time only every (37*29) seconds = 1073s or ~17 minutes. Only once every ~9 hours the three instances will be run at the same time. Admit it: that’s pretty cool 😎 .


And that’s it: my configuration is here to stay for a long time because i3blocks has proven a reliable piece of software so far. It can be customized and extended as much as needed, still keeping a nice integration with i3bar.

A few details here and there might eventually change since I am not using i3blocks to its full potential. I don’t want to over-complicate things, anyway, although there are nice ideas in the i3block-contrib repo linked above (and some in my head, too!). I’ll keep y’all updated, I promise! Happy blocklets to everyone!

Advertisements

Informazioni su Man from Mars

https://extendedreality.wordpress.com/

Un Commento

  1. Pingback: Visto nel Web – 265 | Ok, panico

Dimmi che ne pensi o fai "Ciao ciao!" con la manina // Share your thoughts or just say "Hello!"

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...

%d blogger hanno fatto clic su Mi Piace per questo: