#!/bin/bash # INIT echo "$$" > "$HOME/.cache/pidofbar" # MODULES update_crypto() { crypto="$(crypto)" } update_cpu() { cpu=" $(grep -o "^[^ ]*" /proc/loadavg)" } update_memory() { memory=" $(free -h | sed -n '2s/\([^ ]* *\)\{2\}\([^ ]*\).*/\2/p')" } update_bat() { local dir="$(echo /sys/class/power_supply/BAT* | sort -n | tail -n1)" bat="$(grep -q Charging "$dir/status" && printf '' || printf '')" bat="$bat $(cat "$dir/capacity")%" } update_vol() { local v; v="$(wpctl get-volume '@DEFAULT_AUDIO_SINK@')" if grep -q 'MUTED' <<< "$v"; then vol='🔇' else vol=" $((10#$(tr -dc '0-9' <<< "$v")))" fi } update_backlight() { local actual_brightness local max_brightness read -r actual_brightness \3]_")" # [ "[]" = "$event" ] && event="" #} # modules that don't update on their own need to be run at the start for getting their initial value update_vol update_backlight display() { xsetroot -name "$crypto | $cpu | $memory | $vol | $backlight | $bat | $time" } # SIGNALING # trap ";display" "RTMIN+n" trap "update_vol;display" "RTMIN" trap "update_backlight;display" "RTMIN+1" trap "update_bat;display" "RTMIN+2" # to update it from external commands ## kill -m "$(cat ~/.cache/pidofbar)" # where m = 34 + n sec=0 while true; do sleep 1 & wait && { [ $((sec % 3600)) -eq 0 ] && update_crypto [ $((sec % 5 )) -eq 0 ] && update_time [ $((sec % 5 )) -eq 0 ] && update_cpu [ $((sec % 5 )) -eq 0 ] && update_memory [ $((sec % 5 )) -eq 0 ] && update_bat [ $((sec % 5 )) -eq 0 ] && display sec="$((sec + 1))" } done