This past August, I had the pleasure of giving my first talk. The topic was Dzen. A great little utility you can find in just about any Unix like operating system that supports X11. This post will illustrate the most basic examples of how Dzen works. For more information please refer to my slides and the scripts that I posted.
Requirements and Outcome
Dzen's only real requirement is X11 and knowledge of a scripting language. It is a simple X application that will display whatever you pipe into it into an X window. Most people tend to use Dzen to build custom panels or status bars, but you could really use it for anything that you'd use an X window for. Some people have built notification systems, some have even built alternative box style contextual menus similar to what you might find in openbox or fluxbox. The examples I presented, show the process I went through to build my own personal panel. The end result can be seen in the screenshot below (click for hi res image).
Please note that I used BASH for all my examples but you can substitute bash with your scripting language of choice. The basic structure of a dzen command looks something like this. You pipe some data into dzen and then specify the dzen window size, placement and duration options (-w = width -h = height -x = x axis -y = y axis)
(echo "Hello World"; sleep 4) | dzen2 -x 50 -y 150 -w 500 -h 500
Next we can add a little formatting to our dzen output. (-bg = background color, -fg = foreground/text color, -fn = font)
(echo "Hello World"; sleep 4) | dzen2 -x 50 -y 150 -w 500 -h 500 -bg ‘#cc0000’ -fg ‘#ffffff’ -fn ‘Roboto:bold:size=22’
Dzen also allows for inline formatting options. The general idea is very similar to css. You can set your default styles in your dzen command, but put your overrides in the string that you pipe into dzen. This becomes useful when you want to do things like use one font for text and another for icon glyphs (check out NerdFonts). A few of the common ones are listed below.
- ^fg(foreground color)
- ^bg(background color)
If you want to display data that gets continuously updated, you can use a loop.
(while true; do echo "^fn(Digital Numbers:size=44)$(date '+%l:%M:%S')"; sleep 1;done) | dzen2 -x 50 -y 150 -w 500 -h 150 -bg ‘#000000’ -fg ‘#ffffff’
Putting it Together
You can put all of these together and build something like a color coded battery level indicator. The example script is battery.sh . The script switches colors and icons depending on the battery level and the battery's charge state. The end result will look like this...
More About Dzen
As I stated at the beginning of this post, these are just the basics of what was covered at the Dzen presentation. If you would like to go through more examples please refer to my slides and the corresponding scripts in the repo.