Jorisvandijk.com

Future full-stack developer

Why you don't need a bar

Information notification

A bar is used on a Linux Window Manager to display information like the date, time, volume information and maybe most importantly, on which desktop you are. Most people add way more to their bar, like CPU usage, memory usage, system temperature, hard drive space usage, connection state and many many more. It's also a part of the look of your desktop which you're supposed to rice, screenshot and put on /r/unixporn.

I don't use a bar. I used to, as that was the thing people did, but it annoyed me to lose a line of screen real estate which is just sitting there, hardly getting looked at. Only when I wanted to know the time, I'd look at my bar. Hence the bar went the way of the Dodo and I used my wristwatch for the time... for a while at least. I have to admit, being able to display the time on-screen is worth something, but having it always there is pointless. So I wrote a script. A simple script which took the time from the "date" command and displayed that on the screen through a notification. Pressing a keybinding showed the time.

As with bar-people I ended up adding more and more information to my notification, mainly because I could. I now have a pretty extensive script that will show all sorts of information on key press. The way it looks on my system can be seen in the top right of the screenshot above.

Adding and removing things to be displayed is easy by commenting out lines in the script. I figured others might like to try switching away from the bar and this could be useful.

#!/usr/bin/env bash

# Info 2.1
# Shows time, date and battery information in a notification.
# Dependencies: acpi, libnotify, jq, i3, nerdfonts
#
# By Joris van Dijk | Jorisvandijk.com
# Licensed under the GNU General Public License v3.0

battery() {
batstat="$(cat /sys/class/power_supply/BAT0/status)"
battery="$(cat /sys/class/power_supply/BAT0/capacity)"

if [[ $batstat = 'Unknown' ]] || [[ $batstat = 'Charging' ]]; then
batstat=""
elif [[ $battery -ge 5 ]] && [[ $battery -le 19 ]]; then
batstat=""
elif [[ $battery -ge 20 ]] && [[ $battery -le 39 ]]; then
batstat=""
elif [[ $battery -ge 40 ]] && [[ $battery -le 59 ]]; then
batstat=""
elif [[ $battery -ge 60 ]] && [[ $battery -le 79 ]]; then
batstat=""
elif [[ $battery -ge 80 ]] && [[ $battery -le 95 ]]; then
batstat=""
elif [[ $battery -ge 96 ]] && [[ $battery -le 100 ]]; then
batstat=""
fi

echo $batstat $battery"%"
}

datetime() {
if [[ $1 = 'd' ]]; then
icon=""
info="$(date "+%A %-d/%-m/%Y")"
elif [[ $1 = 't' ]]; then
icon=""
info="$(date "+%H:%M")"
else
icon=""
info="Incorrect or missing flag"
fi

echo $icon $info
}

volume () {
vol="$(pamixer --get-volume)"

if [[ $(pamixer --get-mute) == "true" ]]; then
icon="婢"
elif [[ $vol -ge 0 ]] && [[ $vol -le 33 ]]; then
icon="奄"
elif [[ $vol -ge 34 ]] && [[ $vol -le 66 ]]; then
icon="奔"
else
icon="墳"
fi

echo $icon $vol
}

workspace() {
icon=" "
ws="$(i3-msg -t get_workspaces | jq '.[] | select(.focused==true).name' \
| cut -d"
\"" -f2)"

echo $icon $ws
}

vpn() {
pid=$(pidof openconnect)
if [[ $pid ]]; then
icon=""
VPN="VPN connected"

echo $icon $VPN
else
echo " "
fi
}

# Comment out options to hide them
options=( \
"datetime t" \
"datetime d" \
"battery" \
"workspace" \
"volume" \
"vpn")

for i in "${options[@]}"
do
notify-send -u normal -t 5000 "$($i)"
done

As always, an up to date version of this script can be found in my dotfiles repository. Also, any suggestions regarding the script are welcomed.