Skip to content

Instantly share code, notes, and snippets.

View sarcasticsimba's full-sized avatar

Vignesh sarcasticsimba

View GitHub Profile
full=$(pmset -g batt | { read; read n full; echo "$full"; })
batt=$(echo "$full" | cut -d';' -f1 | tr -d '%')
status=$(echo "$full" | cut -d';' -f2 | tr -d ' ')
time=$(echo "$full" | cut -d';' -f3 | sed 's/^ *//')
noc=$'\e[39m'
if (($batt >= 66)); then battc=$'\e[32m';
elif (($batt >= 33)); then battc=$'\e[33m';
else battc=$'\e[31m';
fi;
ps xro %cpu=,comm= | while read cpu comm; ((i++<5)); do
int=$cpu
int="${int%%.*}"
if (($int >= 50)); then color=$'\e[31m';
elif (($int >= 25)); then color=$'\e[33m';
else color=$'\e[32m';
fi;
echo "$color$cpu% $(basename "$comm")"$'\e[0m'"";