From a0655a2088282eedc184dc3195b2eda0a01f2c83 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Fri, 26 Jun 2020 19:28:15 +0200 Subject: feat: added simple status bar --- bin/status | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100755 bin/status (limited to 'bin') diff --git a/bin/status b/bin/status new file mode 100755 index 0000000..a16ee34 --- /dev/null +++ b/bin/status @@ -0,0 +1,147 @@ +#!/bin/sh + +# 1: last minute +cpu() { + CPULOAD=$(cut -d " " -f 1 /proc/loadavg) + printf " (%s%%)" "$CPULOAD" +} + +mail() { + NEWMAIL=$(ls -s ~/mail/*/INBOX/new | awk '{if ($1 == "total") { sum += $2} }; END {print sum}') + + if [ "${NEWMAIL%% *}" -eq 0 ]; then + printf " (%s)" "${NEWMAIL%% *}" + else + printf " (%s)" "${NEWMAIL%% *}" + fi +} + +battery() { + CHARGE=$(cat /sys/class/power_supply/BAT0/capacity) + STATUS=$(cat /sys/class/power_supply/BAT0/status) + if [ "$STATUS" = "Charging" ]; then + printf " %s%%" "$CHARGE" + else + if [ "$CHARGE" -le 30 ]; then + printf " %s%%" "$CHARGE" + elif [ "$CHARGE" -le 60 ]; then + printf " %s%%" "$CHARGE" + elif [ "$CHARGE" -le 90 ]; then + printf " %s%%" "$CHARGE" + else + printf " %s%%" "$CHARGE" + fi + fi +} + +volume() { + VOL=$(amixer get Master | tail -n1 | sed -r "s/.*\[(.*)%\].*/\1/") + + if [ "$VOL" -eq 0 ]; then + printf "🔇" + elif [ "$VOL" -gt 0 ] && [ "$VOL" -le 33 ]; then + printf "🔈%s%%" "$VOL" + elif [ "$VOL" -gt 33 ] && [ "$VOL" -le 66 ]; then + printf "🔉%s%%" "$VOL" + else + printf "🔊%s%%" "$VOL" + fi +} + +memory() { + USED=$(free | awk '(NR == 2) {print $3}') + TOTL=$(free | awk '(NR == 2) {print $2}') + FRAC=$(tail -c 3 <<< $((${USED}00/$TOTL))) + USED=$(free -h | awk '(NR == 2) {print $3}') + + printf " %s(%d%%)" "$USED" "$FRAC" +} + +weather() { + curl wttr.in?format="%c+%t" +} + +datetime() { + date '+%Y-%m-%d %A %H:%M' +} + +ipaddr() { + for i in $(ip r); do echo "$i"; done | grep -A 1 src | tail -n1 +} + +dostatus() { + # xsetroot -name "$VOL│$BAT│$MEM│$IP│$CPU│$NML│$WTR│$TIM" + echo "$VOL│$BAT│$MEM│$IP│$CPU│$NML│$WTR│$TIM" +} + +# signal handlers +refresh_volume() { + VOL=$(volume) +} + + +refresh_battery() { + BAT=$(battery) +} + +refresh_ip() { + IP=$(ipaddr) +} + + +refresh_cpu() { + CPU=$(cpu) +} + +refresh_mail() { + NML=$(mail) +} + +refresh_weather() { + WTR=$(weather) +} + +refresh_time() { + TIM=$(datetime) +} + +refresh_all() { + refresh_volume + refresh_battery + refresh_ip + refresh_cpu + refresh_mail + refresh_weather + refresh_time +} + +trap "refresh_volume" 35 +trap "refresh_battery" 36 +trap "refresh_ip" 37 +trap "refresh_cpu" 38 +trap "refresh_weather" 39 +trap "refresh_time" 40 +trap "refresh_all" 41 + +PID=$$ +{ +while true # ip address +do + kill -37 $PID + sleep 2h +done & +while true # weather +do + kill -39 $PID + sleep 1d +done & +while true # time +do + BAT=$(battery) + TIM=$(datetime) + CPU=$(cpu) + NML=$(mail) + dostatus + sleep 1m & wait $! +done +} -- cgit v1.2.1