summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDdone <mykyta.poturai@gmail.com>2020-07-02 18:01:45 +0300
committerGitHub <noreply@github.com>2020-07-02 11:01:45 -0400
commit93f3711e3958b2ee3bc4ccc2def7fddf0d578584 (patch)
treec0f657eb8863ddf1ff6a602cc1faa34d2a0f5368
parentf11008c619e1746d0d3f25c471343c1591200941 (diff)
downloadeibhear-93f3711e3958b2ee3bc4ccc2def7fddf0d578584.tar.gz
eibhear-93f3711e3958b2ee3bc4ccc2def7fddf0d578584.tar.zst
eibhear-93f3711e3958b2ee3bc4ccc2def7fddf0d578584.zip
Add cpubars script for dwmblocks (#736)
This script shows CPU load
-rwxr-xr-x.local/bin/statusbar/cpubars45
1 files changed, 45 insertions, 0 deletions
diff --git a/.local/bin/statusbar/cpubars b/.local/bin/statusbar/cpubars
new file mode 100755
index 0000000..d960727
--- /dev/null
+++ b/.local/bin/statusbar/cpubars
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+# Module showing CPU load as a changing bars.
+# Just like in polybar.
+# Each bar represents amount of load on one core since
+# last run.
+
+# Cache in tmpfs to improve speed and reduce SSD load
+cache=/tmp/cpubarscache
+
+case $BLOCK_BUTTON in
+ 2) setsid -f "$TERMINAL" -e htop ;;
+ 3) notify-send "🪨 CPU load module" "Each bar represents
+one CPU core";;
+ 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
+esac
+
+# id total idle
+stats=$(awk '/cpu[0-9]+/ {printf "%d %d %d\n", substr($1,4), ($2 + $3 + $4 + $5), $5 }' /proc/stat)
+[ ! -f $cache ] && echo "$stats" > "$cache"
+old=$(cat "$cache")
+echo -n "🪨"
+echo "$stats" | while read row; do
+ id=${row%% *}
+ rest=${row#* }
+ total=${rest%% *}
+ idle=${rest##* }
+
+ case "$(echo "$old" | awk '{if ($1 == id)
+ printf "%d\n", (1 - (idle - $3) / (total - $2))*100 /12.5}' \
+ id=$id total=$total idle=$idle)" in
+
+ "0") echo -n "▁";;
+ "1") echo -n "▂";;
+ "2") echo -n "▃";;
+ "3") echo -n "▄";;
+ "4") echo -n "▅";;
+ "5") echo -n "▆";;
+ "6") echo -n "▇";;
+ "7") echo -n "█";;
+ "8") echo -n "█";;
+ esac
+done
+echo ""
+echo "$stats" > "$cache"