[status] feat: add sb-cpu
This commit is contained in:
parent
03a7796555
commit
7ab5d2909b
37
.local/bin/statusbar/sb-cpu
Executable file
37
.local/bin/statusbar/sb-cpu
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# Module showing CPU load as a changing bars.
|
||||
# Just like in polybar.
|
||||
# Each bar represents amount of load on one core since
|
||||
# last run.
|
||||
|
||||
# Cache in tmpfs to improve speed and reduce SSD load
|
||||
cache=/tmp/cpubarscache
|
||||
|
||||
# id total idle
|
||||
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")
|
||||
printf " %s " " "
|
||||
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
|
||||
|
||||
"0") printf "▁";;
|
||||
"1") printf "▂";;
|
||||
"2") printf "▃";;
|
||||
"3") printf "▄";;
|
||||
"4") printf "▅";;
|
||||
"5") printf "▆";;
|
||||
"6") printf "▇";;
|
||||
"7") printf "█";;
|
||||
"8") printf "█";;
|
||||
esac
|
||||
done; printf " \\n"
|
||||
echo "$stats" > "$cache"
|
@ -1 +1 @@
|
||||
Subproject commit b78f4dc620d0ab9eb6e70eace07263b2c1f9a66c
|
||||
Subproject commit 5c9090ae551a08e13201b92d63bcff8110264f23
|
Reference in New Issue
Block a user