aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/awesome-widgets/widget-cpu_usage
diff options
context:
space:
mode:
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"