optimizing sb-cpu
This commit is contained in:
parent
698aed64f1
commit
94b2de92aa
1 changed files with 22 additions and 7 deletions
|
@ -1,4 +1,6 @@
|
|||
#!/bin/sh
|
||||
# WARN: This is largely untested with the new pango changes
|
||||
# If the colors change too often it could result in the statusbar disappearing
|
||||
. "$HOME/.local/libexec/statusbar/colors"
|
||||
|
||||
cache=/tmp/cpubarscache
|
||||
|
@ -8,6 +10,8 @@ stats=$(awk '/cpu[0-9]+/ {printf "%d %d %d\n", substr($1,4), ($2 + $3 + $4 + $5)
|
|||
[ ! -f $cache ] && echo "$stats" >"$cache"
|
||||
old=$(cat "$cache")
|
||||
printf "%b" " $temp"
|
||||
|
||||
first=true
|
||||
echo "$stats" | while read -r row; do
|
||||
id=${row%% *}
|
||||
rest=${row#* }
|
||||
|
@ -18,13 +22,24 @@ echo "$stats" | while read -r row; do
|
|||
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
|
||||
"0") printf "%b" "<span $fggreen>▁</span>" ;;
|
||||
"1") printf "%b" "<span $fggreen>▂</span>" ;;
|
||||
"2") printf "%b" "<span $fggreen>▃</span>" ;;
|
||||
"3") printf "%b" "<span $fgorange>▄</span>" ;;
|
||||
"4") printf "%b" "<span $fgorange>▅</span>" ;;
|
||||
"5") printf "%b" "<span $fgorange>▆</span>" ;;
|
||||
"6" | "7" | "8") printf "%b" "<span $fgred>▇</span>" ;;
|
||||
"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=▇ ;;
|
||||
esac
|
||||
if [ "$col" != "$prevcol" ]; then
|
||||
[ "$first" != "true" ] && printf "%b" "</span>"
|
||||
printf "%b" "<span $col>"
|
||||
fi
|
||||
printf "%b" "$icon"
|
||||
|
||||
first=false
|
||||
prevcol=$col
|
||||
done
|
||||
|
||||
printf "%b" "</span>"
|
||||
|
||||
echo "$stats" >"$cache"
|
||||
|
|
Loading…
Add table
Reference in a new issue