#!/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") printf "\e[11m\e[10m " 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 "\e[32m▁" ;; "1") printf "\e[32m▂" ;; "2") printf "\e[32m▃" ;; "3") printf "\e[33m▄" ;; "4") printf "\e[33m▅" ;; "5") printf "\e[33m▆" ;; "6" | "7" | "8") printf "\e[31m▇" ;; esac done printf "\e[0m\n" echo "$stats" >"$cache"