dotfiles

<-- duh.
Log | Files | Refs | LICENSE

commit 040b621f1028e6db52917db69518767a6061c1eb
parent 19e0a15a762b68c5a8bc185c538b43eb787e5661
Author: hhvn <dev@hhvn.uk>
Date:   Fri,  3 Dec 2021 17:05:58 +0000

.s/d/cpu: visual usage

Diffstat:
M.scripts/dwmblocks/cpu | 53++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 50 insertions(+), 3 deletions(-)

diff --git a/.scripts/dwmblocks/cpu b/.scripts/dwmblocks/cpu @@ -1,12 +1,59 @@ #!/bin/sh -cpu=$(ps -e -o %cpu | awk '{s+=$1} END {print s}' | sed 's/\..*$//g') tempt=$(acpi -t | awk '{s+=$4} END {print s}') tempc=$(acpi -t | wc -l) temp=$(($tempt/$tempc)) -temp=" $temp" +temp="$temp" [ $temp -gt 55 ] && [ ! $temp -gt 70 ] && temp="^c#aa7700^$temp" [ $temp -gt 60 ] && temp="^c#aa0000^$temp" [ $temp -lt 55 ] && temp="^c#aaaa00^$temp" [ $temp -lt 50 ] && temp="^c#00aa00^$temp" -echo "[^c#7777cc^C^d^$cpu%${temp}C]" + +cpu=$( + ( + cat /proc/stat + sleep 1 + cat /proc/stat + ) | awk ' + BEGIN { + pass = 0; + height = 10; # pixels + } + + /intr/ { pass = 1; } + + /^cpu[0-9][0-9]*/ && !pass { + sub(/cpu/, "", $1); + total = 0; + for (i = 2; i <= NF; i++) + total = total + $i; + ctotal[$1] = total; + cidle[$1] = $5; + } + + /^cpu[0-9][0-9]*/ && pass { + sub(/cpu/, "", $1); + total = 0; + for (i = 2; i <= NF; i++) + total += $i; + diff = total - ctotal[$1]; + idle = $5 - cidle[$1]; + used = diff - idle; + decimal = used / diff; + barheight = decimal * height; + + if (decimal > 0.8) + col = "^c#aa0000^"; + else if (decimal > 0.5) + col = "^c#aa7700^"; + else + col = "^c#00aa00^"; + + printf("^c#000000^^r0,2,5,1^^r0,3,1,%d^^f1^%s^r0,%d,3,%d^^c#000000^^r0,12,3,1^^f3^^r0,3,1,%d^^f2^", + height, + col, (height - barheight + 3), barheight, + height); + }' +) + +echo "[^f1^$cpu^d^${temp}C]"