summaryrefslogtreecommitdiff
path: root/mut/bin/spectrwmbar
diff options
context:
space:
mode:
authorMike Vink <mike1994vink@gmail.com>2023-10-06 23:10:55 +0200
committerMike Vink <mike1994vink@gmail.com>2023-10-06 23:10:55 +0200
commitcfaef26e8718916adcc68fbfb63b15f2389b2cd2 (patch)
tree3989af4514d31d0a5cb89e8b96d51210ad7bf152 /mut/bin/spectrwmbar
parent654ec06ab6a885ea851c4cbf68d06a00b41b0e14 (diff)
move all the files
Diffstat (limited to 'mut/bin/spectrwmbar')
-rw-r--r--mut/bin/spectrwmbar59
1 files changed, 59 insertions, 0 deletions
diff --git a/mut/bin/spectrwmbar b/mut/bin/spectrwmbar
new file mode 100644
index 0000000..a106b01
--- /dev/null
+++ b/mut/bin/spectrwmbar
@@ -0,0 +1,59 @@
+#!/usr/bin/env sh
+# script for spectrwm status bar
+
+trap 'update' 5
+
+fgcolors=("+@fg=1;" "+@fg=2;" "+@fg=3;" "+@fg=4;" "+@fg=5;" "+@fg=6;" "+@fg=7;" "+@fg=8;")
+nfgcolors=${#fgcolors[@]}
+
+SLEEP_SEC=5m
+
+repeat() {
+ i=0; while [ $i -lt $1 ]
+ do
+ echo -ne "$TOKEN"
+ i=$(( i + 1 ))
+ done
+}
+
+cpu() {
+ read cpu a b c previdle rest < /proc/stat
+ prevtotal=$((a+b+c+previdle))
+ sleep 0.5
+ read cpu a b c idle rest < /proc/stat
+ total=$((a+b+c+idle))
+ cpu=$((100*( (total-prevtotal) - (idle-previdle) ) / (total-prevtotal) ))
+ echo -e "CPU: $cpu%"
+}
+
+battery() {
+ BATTERY="$(cat /sys/class/power_supply/BAT0/capacity)"
+
+ BAR_LEFT=$BATTERY
+ BATTERY_BAR=""
+ BLOCK=$(( 100 / nfgcolors ))
+ TOKEN=$(printf '\u2588')
+
+ BAT_COL=$(( $nfgcolors -1 ))
+ #loops forever outputting a line every SLEEP_SEC secs
+ while [ $(( BAR_LEFT - BLOCK )) -gt 0 ]
+ do
+ BATTERY_BAR="${fgcolors[$BAT_COL]}$(repeat $BLOCK)${BATTERY_BAR}"
+ BAR_LEFT=$(( BAR_LEFT - BLOCK ))
+ BAT_COL=$(( BAT_COL - 1))
+ done
+
+ BATTERY_BAR="BATTERY: ${fgcolors[$BAT_COL]}$(repeat $BAR_LEFT)${BATTERY_BAR}"
+ echo $BATTERY_BAR
+}
+
+update() {
+ echo "$(cpu) $(battery)"
+ wait
+}
+
+while :; do
+ update
+ sleep $SLEEP_SEC &
+ wait
+done