aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/awesome-widgets/widget-cpu_usage
diff options
context:
space:
mode:
authorBlista Kanjo2023-07-18 19:22:58 -0400
committerBlista Kanjo2023-07-18 19:22:58 -0400
commit4a439d18320b1d993156a99a9796c37dbb055b7c (patch)
treeadf008387814d02822a7271dd8adb05c2da781e8 /.local/bin/awesome-widgets/widget-cpu_usage
parent4366404defb751f8acb35ffa6566664a5ec11f7f (diff)
feat: trying out some `dwmblocks`-style widgets
Diffstat (limited to '.local/bin/awesome-widgets/widget-cpu_usage')
-rwxr-xr-x.local/bin/awesome-widgets/widget-cpu_usage31
1 files changed, 31 insertions, 0 deletions
diff --git a/.local/bin/awesome-widgets/widget-cpu_usage b/.local/bin/awesome-widgets/widget-cpu_usage
new file mode 100755
index 0000000..14997fd
--- /dev/null
+++ b/.local/bin/awesome-widgets/widget-cpu_usage
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+# Cache in tmpfs to improve speed and reduce SSD load
+cache=/tmp/cpubarscache
+
+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")
+printf " 📊 "
+echo "$stats" | while read -r 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") printf "▁";;
+ "1") printf "▂";;
+ "2") printf "▃";;
+ "3") printf "▄";;
+ "4") printf "▅";;
+ "5") printf "▆";;
+ "6") printf "▇";;
+ "7") printf "█";;
+ "8") printf "█";;
+ esac
+done; printf "\\n"
+echo "$stats" > "$cache"