#!/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; 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 while [ -z "$(wpctl get-volume '@DEFAULT_AUDIO_SINK@' 2> /dev/null)" ]; do sleep 1 done update_vol reload_bar() { sec=0 } display() { xsetroot -name "$crypto | $cpu | $memory | $vol | $time" } # SIGNALING # trap ';display' 'RTMIN+n' trap 'reload_bar;display' 'RTMIN' trap 'update_vol;display' 'RTMIN+1' trap 'update_backlight;display' 'RTMIN+2' trap 'update_crypto;display' 'RTMIN+3' # to update it from external commands ## kill -m "$(cat ~/.cache/pidofbar)" # where m = 34 + n sec=0 while true; do [ "$((sec % 3600))" = 0 ] && update_crypto [ "$((sec % 5 ))" = 0 ] && { update_time update_cpu update_memory display } sleep 1 & wait sec="$((sec + 1))" done