2022-07-04 21:36:33 +02:00
|
|
|
#!/bin/sh
|
|
|
|
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")
|
2022-08-22 20:33:37 +02:00
|
|
|
printf "\033[11m\033[10m "
|
2022-07-04 21:36:33 +02:00
|
|
|
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
|
2022-09-15 20:27:44 +02:00
|
|
|
"0") printf "\033[32m▁";;
|
|
|
|
"1") printf "\033[32m▂";;
|
|
|
|
"2") printf "\033[32m▃";;
|
|
|
|
"3") printf "\033[33m▄";;
|
|
|
|
"4") printf "\033[33m▅";;
|
|
|
|
"5") printf "\033[33m▆";;
|
|
|
|
"6"|"7"|"8") printf "\033[31m▇";;
|
2022-08-22 20:33:37 +02:00
|
|
|
|
2022-07-04 21:36:33 +02:00
|
|
|
esac
|
2022-09-21 21:46:27 +02:00
|
|
|
done; printf "\033[0m\n"
|
2022-07-04 21:36:33 +02:00
|
|
|
echo "$stats" > "$cache"
|