2022-07-04 21:36:33 +02:00
|
|
|
#!/bin/sh
|
2024-02-03 18:57:14 +01:00
|
|
|
# WARN: This is largely untested with the new pango changes
|
|
|
|
# If the colors change too often it could result in the statusbar disappearing
|
2024-02-03 17:52:33 +01:00
|
|
|
. "$HOME/.local/libexec/statusbar/colors"
|
2023-05-31 11:27:31 +02:00
|
|
|
|
2024-02-08 17:04:57 +01:00
|
|
|
cache=$XDG_RUNTIME_DIR/cpubarscache
|
|
|
|
|
2023-06-15 13:27:35 +02:00
|
|
|
temp=$(sensors | awk '/CPU/ {printf ("%.f°C", $2)}' | tr -d "+")
|
2024-01-17 12:37:27 +01:00
|
|
|
[ -n "$temp" ] && temp="$temp "
|
|
|
|
stats=$(awk '/cpu[0-9]+/ {printf "%d %d %d\n", substr($1,4), ($2 + $3 + $4 + $5), $5 }' /proc/stat 2>/dev/null)
|
2024-02-08 17:04:57 +01:00
|
|
|
|
|
|
|
[ ! -f "$cache" ] && echo "$stats" >"$cache" && exit
|
2023-05-31 11:27:31 +02:00
|
|
|
old=$(cat "$cache")
|
2024-02-03 19:25:22 +01:00
|
|
|
printf "%b" " $temp"
|
2024-02-03 18:57:14 +01:00
|
|
|
|
|
|
|
first=true
|
2023-05-31 11:27:31 +02:00
|
|
|
echo "$stats" | while read -r row; do
|
|
|
|
id=${row%% *}
|
|
|
|
rest=${row#* }
|
|
|
|
total=${rest%% *}
|
|
|
|
idle=${rest##* }
|
2024-02-03 17:52:33 +01:00
|
|
|
case "$(
|
|
|
|
echo "$old" |
|
|
|
|
awk '{if ($1 == id) printf "%d\n", (1 - (idle - $3) / (total - $2))*100 /12.5}' \
|
|
|
|
id="$id" total="$total" idle="$idle" 2>/dev/null
|
|
|
|
)" in
|
2024-02-03 18:57:14 +01:00
|
|
|
"0") col=$fggreen icon=▁ ;;
|
|
|
|
"1") col=$fggreen icon=▂ ;;
|
|
|
|
"2") col=$fggreen icon=▃ ;;
|
|
|
|
"3") col=$fgorange icon=▄ ;;
|
|
|
|
"4") col=$fgorange icon=▅ ;;
|
|
|
|
"5") col=$fgorange icon=▆ ;;
|
|
|
|
"6" | "7" | "8") col=$fgred icon=▇ ;;
|
2023-05-31 11:27:31 +02:00
|
|
|
esac
|
2024-02-03 18:57:14 +01:00
|
|
|
if [ "$col" != "$prevcol" ]; then
|
|
|
|
[ "$first" != "true" ] && printf "%b" "</span>"
|
|
|
|
printf "%b" "<span $col>"
|
|
|
|
fi
|
|
|
|
printf "%b" "$icon"
|
|
|
|
|
|
|
|
first=false
|
|
|
|
prevcol=$col
|
2023-05-31 11:27:31 +02:00
|
|
|
done
|
2024-02-03 18:57:14 +01:00
|
|
|
|
|
|
|
printf "%b" "</span>"
|
|
|
|
|
2023-05-31 11:27:31 +02:00
|
|
|
echo "$stats" >"$cache"
|