2022-07-04 21:36:33 +02:00
|
|
|
#!/bin/sh
|
2023-05-24 18:33:43 +02:00
|
|
|
|
|
|
|
reset="\033[0m"
|
|
|
|
normal="\033[10m"
|
|
|
|
big="\033[11m"
|
|
|
|
red="\033[31m"
|
|
|
|
green="\033[32m"
|
|
|
|
orange="\033[33m"
|
|
|
|
|
2022-07-04 21:36:33 +02:00
|
|
|
cache=/tmp/cpubarscache
|
|
|
|
stats=$(awk '/cpu[0-9]+/ {printf "%d %d %d\n", substr($1,4), ($2 + $3 + $4 + $5), $5 }' /proc/stat)
|
2023-02-07 17:19:53 +01:00
|
|
|
[ ! -f $cache ] && echo "$stats" >"$cache"
|
2022-07-04 21:36:33 +02:00
|
|
|
old=$(cat "$cache")
|
2023-05-24 18:33:43 +02:00
|
|
|
printf "%b" "$big$normal "
|
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
|
2023-05-24 18:33:43 +02:00
|
|
|
"0") printf "%b" "$green▁" ;;
|
|
|
|
"1") printf "%b" "$green▂" ;;
|
|
|
|
"2") printf "%b" "$green▃" ;;
|
|
|
|
"3") printf "%b" "$orange▄" ;;
|
|
|
|
"4") printf "%b" "$orange▅" ;;
|
|
|
|
"5") printf "%b" "$orange▆" ;;
|
|
|
|
"6" | "7" | "8") printf "%b" "$red▇" ;;
|
2022-08-22 20:33:37 +02:00
|
|
|
|
2022-07-04 21:36:33 +02:00
|
|
|
esac
|
2023-02-07 17:19:53 +01:00
|
|
|
done
|
2023-05-24 18:33:43 +02:00
|
|
|
printf "%b" "$reset\n"
|
2023-02-07 17:19:53 +01:00
|
|
|
echo "$stats" >"$cache"
|