diff options
| author | ivan-boikov <ik.boikov.public@protonmail.com> | 2022-07-14 23:51:06 +0200 |
|---|---|---|
| committer | ivan-boikov <ik.boikov.public@protonmail.com> | 2022-07-14 23:51:06 +0200 |
| commit | 47eb75b4250badd24b3137f77bf237e6f0570b15 (patch) | |
| tree | 3ea591e70b3e5f6e9a4dd7005904d9226f1b6891 /scripts/.local/bin/sb-cpubars | |
| parent | 919fe5982b47278ef34a30d3b08af41e1ddd1b11 (diff) | |
1
Diffstat (limited to 'scripts/.local/bin/sb-cpubars')
| -rwxr-xr-x | scripts/.local/bin/sb-cpubars | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/.local/bin/sb-cpubars b/scripts/.local/bin/sb-cpubars new file mode 100755 index 0000000..946f9ef --- /dev/null +++ b/scripts/.local/bin/sb-cpubars @@ -0,0 +1,37 @@ +#!/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 + +# 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") +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" |
