Skip to content

Instantly share code, notes, and snippets.

@sarcasticsimba
Created November 7, 2014 02:42
Show Gist options
  • Save sarcasticsimba/56f0611dcefe199afc7f to your computer and use it in GitHub Desktop.
Save sarcasticsimba/56f0611dcefe199afc7f to your computer and use it in GitHub Desktop.
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'"";
done
@mansante
Copy link

to prevent error when "-zsh" command is displayed:

echo "$color$cpu% $(basename "$(echo $comm | sed -e 's/-//')")"$'\e[0m'"";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment