#!/bin/sh -u
volume() {
volume=$(pactl get-sink-volume @DEFAULT_SINK@ | sed -nE 's/.*\s([0-9]+)%.*/\1/p')
if [ "$(pactl get-sink-mute @DEFAULT_SINK@)" = "Mute: yes" ]; then
volume_symbol=""
elif [ "$volume" -eq 0 ]; then
volume_symbol=""
elif [ "$volume" -le 50 ]; then
volume_symbol=""
else
volume_symbol=""
fi
printf '%s %d%%' "$volume_symbol" "$volume"
}
network() {
ssid=$(iwgetid -r)
if [ -n "$ssid" ]; then
symbol=" "
else
symbol=""
fi
printf '%s %s' "$symbol" "$ssid"
}
brightness() {
brightness=$(brightnessctl -m | awk -F, '{ print $4 }')
printf ' %s' "$brightness"
}
battery() {
status=$(cat /sys/class/power_supply/BAT0/status)
capacity=$(cat /sys/class/power_supply/BAT0/capacity)
idx=$(((capacity - 1) / 10 + 1))
case "$status" in
"Discharging")
symbol=$(echo ',,,,,,,,,' |
awk -F, "{ print \$$idx }")
;;
"Charging")
symbol=$(echo " " | awk "{ print \$$idx }")
;;
"Full")
symbol=""
;;
esac
printf '%s %d%%' "$symbol" "$capacity"
}
clock() {
printf ' %s' "$(date '+%b %d %H:%M')"
}
while true; do
somebar -c status "$(volume) | $(network) | $(brightness) | $(battery) | $(clock)"
sleep 0.2
done