Time for real configuration of the status bar. In today’s article of the FreeBSD Desktop series I will describe how to configure the Dzen2.
You may also check earlier articles of the FreeBSD Desktop series:
- FreeBSD Desktop – Part 1 – Simplified Boot
- FreeBSD Desktop – Part 2 – Install
- FreeBSD Desktop – Part 3 – X11 Window System
- FreeBSD Desktop – Part 4 – Key Components – Window Manager
- FreeBSD Desktop – Part 5 – Key Components – Status Bar
- FreeBSD Desktop – Part 6 – Key Components – Task Bar
- FreeBSD Desktop – Part 7 – Key Components – Wallpaper Handling
- FreeBSD Desktop – Part 8 – Key Components – Application Launcher
- FreeBSD Desktop – Part 9 – Key Components – Keyboard/Mouse Shortcuts
- FreeBSD Desktop – Part 10 – Key Components – Locking Solution
- FreeBSD Desktop – Part 11 – Key Components – Blue Light Spectrum Suppress
- FreeBSD Desktop – Part 12 – Configuration – Openbox
- FreeBSD Desktop – Part 13 – Configuration – Dzen2
- FreeBSD Desktop – Part 14 – Configuration – Tint2
Features
The provided status bar backed by Dzen2 will be providing the following information.
- date: Date in ISO 8601 format along with current time.
- sys: CPU frequency, CPU temperature, system load and free RAM.
- ip: List of current IP addresses and its interfaces.
- gw: System default network gateway.
- dns: System default DNS.
- ping: Current Internet access state.
- vol/pcm: Volume level for vol and pcm backends.
- fs: ZFS pools free space.
- bat: Battery and AC status.
- top: Top 3 processes with highest CPU usage along with their RAM usage.
Here is how such Dzen2 looks like in action.

Dzen2
The Dzen2 offers feature that Conky or other status bar applications does not offer. I would call it refresh on demand. If you would like to implement refresh interval of 60 seconds for example (not so often) and also refresh that information everytime you ‘click’ on the status bar (or by other action) its possible to implement in Dzen2 using mkfifo(1) command.
Why anyone would want to implement such ‘strange’ refresh policy? To get more battery life mostly as You do not need this information to be refreshed every second and if You need up to date information then you will refresh it manually with a click on the status bar and have the needed information. The other reason is ‘focus’. If this status bar refreshes every second, then it ‘caches’ your attention, this may prevent you from focusing deep enough on the task you are currently doing. If you do something important that requires focus then You do not want status bar (or anything else) to distract you with useless at the moment information.
To achieve such configuration we would need three things. The dzen2-fifo.sh script that will start initial fifo on the ~/.dzen2-fifo file. The dzen2-update.sh to update the fifo and would be run from the crontab(1) every 60 seconds. A dzen2(1) action configured with left mouse button click to invoke dzen2-update.sh to update the fifo. All these scripts and scripts used directly by Dzen2 to gather needed information are available in the scripts-status-bar.tar.gz file.
To start Dzen2 at the X11 startup we will use script from the earlier ‘bulk’ already available – __openbox_restart_dzen2.sh – which kills all instances of Dzen2 and then starts the fifo backed Dzen2 with dzen2-fifo.sh script available in the scripts.tar.gz file.
Here is how its configured in the ~/.xinitrc (or ~/.xsession) file.
% grep dzen ~/.xinitrc ~/scripts/__openbox_restart_dzen2.sh &
Remember to put ‘&‘ at the end of the line.
Lets have a look how the ‘update’ is configured in the crontab(1) as shown below.
% crontab -l # DZEN2 0 * * * * ~/scripts/dzen2-update.sh 1> ~/.dzen2-fifo 2> /dev/null
The scripts that Dzen2 uses to gather information are:
~/scripts/__conky_if_ip.sh
~/scripts/__conky_if_gw.sh
~/scripts/__conky_if_dns.sh
~/scripts/__conky_if_ping.sh
~/scripts/__conky_battery.sh
… and this one to ’emulate’ clicks to implement Openbox virtual desktops switching with [Scroll Up] and [Scroll Down] mouse events.
~/scripts/xdotool.sh
The dzen2-update.sh is kinda like Conky on terminal, it just puts all that information in text format with Dzen2 colors syntax as shown below.
% dzen2-update.sh ^fg(#aaaaaa)date: ^fg(#eeeeee)2018/07/05/Thu/10:11 ^fg(#dd0000)| ^fg(#aaaaaa)sys: ^fg(#eeeeee)800MHz/46.1C/0.83/4.5GB ^fg(#dd0000)| ^fg(#aaaaaa)ip: ^fg(#eeeeee)wlan0/wirelesssid/192.168.0.3 ^fg(#dd0000)| ^fg(#aaaaaa)gw: ^fg(#eeeeee)192.168.0.1 ^fg(#dd0000)| ^fg(#aaaaaa)dns: ^fg(#eeeeee)192.168.0.1 ^fg(#dd0000)| ^fg(#aaaaaa)ping: ^fg(#eeeeee)^fg(#dd2200)NOPE ^fg(#dd0000)| ^fg(#aaaaaa)vol/pcm: ^fg(#eeeeee)100/100 ^fg(#dd0000)| ^fg(#aaaaaa)fs: ^fg(#eeeeee)local/69.2G sys/3.27G ^fg(#dd0000)| ^fg(#aaaaaa)bat: ^fg(#eeeeee)AC/^fg(#ffffff)90% ^fg(#dd0000)| ^fg(#aaaaaa)top: ^fg(#eeeeee)firefox/15%/0.6GB firefox/13%/0.3GB firefox/11%/0.4GB
Doas
To make most scripts work Your user (vuk in the series) needs to be in the wheel, operator and network groups and doas(1) (sudo(8) equivalent) needs to be installed and configured in the following way.
# pkg install doas # pw groupmod wheel -m vuk # pw groupmod operator -m vuk # pw groupmod network -m vuk # cat /usr/local/etc/doas.conf permit nopass :wheel as root permit nopass :network as root cmd ifconfig permit nopass :network as root cmd dhclient permit nopass :network as root cmd umount permit nopass :network as root cmd wpa_supplicant permit nopass :network as root cmd ppp permit nopass :network as root cmd killall args -9 dhclient permit nopass :network as root cmd killall args -9 wpa_supplicant permit nopass :network as root cmd killall args -9 ppp permit nopass :network as root cmd cat args /etc/ppp/ppp.conf permit nopass :network as root cmd /etc/rc.d/netif args onerestart permit nopass :network as root cmd tee args /etc/resolv.conf permit nopass :network as root cmd tee args -a /etc/resolv.conf
Scripts
In this post I attach scripts related to Dzen2. Download them all in the scripts-status-bar.tar.gz file and unpack them into the ~/scripts directory.
Here are these scripts.
% tar -tf scripts-status-bar.tar.gz ~/scripts/dzen2-fifo.sh ~/scripts/dzen2-update.sh ~/scripts/xdotool.sh ~/scripts/__conky_if_ip.sh ~/scripts/__conky_if_gw.sh ~/scripts/__conky_if_dns.sh ~/scripts/__conky_if_ping.sh ~/scripts/__conky_battery.sh
Make sure they remain executable.
% chmod +x ~/scripts/*
To make them work properly add ~/scripts into the ${PATH} variable at the beginning of the ~/.xinitrc file.
# PATH TO SCRIPTS
export PATH=${PATH}:~/scripts
All of my scripts have this ‘mysterious’ line at the end. Its for statistics to check which scripts are run when (or it at all to which ones to delete).
echo '1' >> ~/scripts/stats/$( basename ${0} )
Thus it is needed to create the ‘stats’ directory.
% mkdir -p ~/scripts/stats
I have implemented that about two months ago and here are the results.
% wc -l ~/scripts/stats/* | sort -n
1 /home/vermaden/scripts/stats/__openbox_show_screenshot.sh
2 /home/vermaden/scripts/stats/__openbox_cpufreq.sh
2 /home/vermaden/scripts/stats/__openbox_current_wallpaper.sh
2 /home/vermaden/scripts/stats/__openbox_fullscreen.sh
4 /home/vermaden/scripts/stats/__openbox_restart_dzen2.sh
4 /home/vermaden/scripts/stats/dzen2-fifo.sh
5 /home/vermaden/scripts/stats/__openbox_dmenu.sh
5 /home/vermaden/scripts/stats/__openbox_restart_conky.sh
5 /home/vermaden/scripts/stats/__openbox_restart_tint2.sh
6 /home/vermaden/scripts/stats/__openbox_delete_wallpaper.sh
7 /home/vermaden/scripts/stats/__openbox_freebsd_sound.sh
8 /home/vermaden/scripts/stats/aero-snap.sh
12 /home/vermaden/scripts/stats/__openbox_edit_screenshot.sh
16 /home/vermaden/scripts/stats/__openbox_lock_zzz.sh
16 /home/vermaden/scripts/stats/__openbox_lock.sh
22 /home/vermaden/scripts/stats/shot.sh
24 /home/vermaden/scripts/stats/network.sh
214 /home/vermaden/scripts/stats/xterm.sh
960 /home/vermaden/scripts/stats/random_wallpaper.sh
2767 /home/vermaden/scripts/stats/desktop-battery-warning.sh
13834 /home/vermaden/scripts/stats/desktop-kill-shit.sh
17916 total
Of course I limited the output only to scripts that are available in this article, but be patient, more to come later 🙂
Dependencies
To make these scripts work and generally to make all this setup work we will need these dependencies.
- dzen2
- xdotool
- wmctrl
To install them all with pkg(8) just type this line below.
# pkg install dzen2 xdotool wmctrl
Crontab
After adding Dzen2 to crontab(1) and keeping the earlier entries the complete crontab(1) would look like that.
% crontab -l # DESKTOP * * * * * ~/scripts/desktop-kill-shit.sh 1> /dev/null 2> /dev/null */5 * * * * ~/scripts/desktop-battery-warning.sh */20 * * * * ~/scripts/random_wallpaper.sh ~/gfx/wallpapers 1> /dev/null 2> /dev/null 12,0 * * * * /usr/bin/find ~/.cache -mtime +10 -delete 1> /dev/null 2> /dev/null 0 */3 * * * /usr/bin/find ~/.local/share/Trash/files -mtime +1 -delete 1> /dev/null 2> /dev/null # DZEN2 0 * * * * ~/scripts/dzen2-update.sh 1> ~/.dzen2-fifo 2> /dev/null
Shortcuts
This Dzen2 configuration implements five ‘mouse actions’ or shortcuts available on the status bar.
[Scroll Up]– switch next virtual desktop.[Scroll Down]– switch previous virtual desktop.[Right Click]– show Openbox root menu.[Middle Click]– show Openbox window menu.[Left Click]– update Dzen2 Status Bar with dzen2-update.sh invoke.
Hope I haven’t forgot anything, feel free to ask or remind me 😉
Looks like adding “permit nopass :wheel as root” to doas.conf and adding the user to group wheel makes all the network related lines in doas.conf redundant.
LikeLike
Yes, I need to ‘rework’ the other scripts to not need ‘root’ but if someone would only need network related things without rest as root then I added it for reference.
LikeLike
Pingback: FreeBSD Desktop – Part 14 – Configuration – Tint2 | vermaden
Pingback: FreeBSD desktop (13) | 0ddn1x: tricks with *nix
Pingback: FreeBSD Desktop – Part 12 – Configuration – Openbox | vermaden
Pingback: FreeBSD Desktop – Part 11 – Key Components – Blue Light Spectrum Suppress | vermaden
Pingback: FreeBSD Desktop – Part 10 – Key Components – Locking Solution | vermaden
Pingback: FreeBSD Desktop – Part 9 – Key Components – Keyboard/Mouse Shortcuts | vermaden
Pingback: FreeBSD Desktop – Part 7 – Key Components – Wallpaper Handling | vermaden
Pingback: FreeBSD Desktop – Part 8 – Key Components – Application Launcher | vermaden
Pingback: FreeBSD Desktop – Part 5 – Key Components – Status Bar | vermaden
Pingback: FreeBSD Desktop – Part 4 – Key Components – Window Manager | vermaden
Pingback: FreeBSD Desktop – Part 15 – Configuration – Fonts & Frameworks | vermaden
Pingback: FreeBSD Desktop – Part 1 – Simplified Boot | vermaden
Pingback: FreeBSD Desktop – Part 2 – Install | vermaden
Pingback: FreeBSD Desktop – Part 3 – X11 Window System | vermaden
Pingback: FreeBSD Desktop – Part 6 – Key Components – Task Bar | vermaden