Add cygwin support

This commit is contained in:
Camille TJHOA 2015-01-29 18:37:18 +01:00
parent a1c753d4ce
commit 00d4e982f7
2 changed files with 8 additions and 1 deletions

View file

@ -5,7 +5,10 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
print_cpu_percentage() {
if [ -e "/proc/stat" ]; then
if [ is_cygwin ]; then
usage="$(WMIC cpu get LoadPercentage | grep -Eo '^[0-9]+')"
printf "%.1f%%" $usage
elif [ -e "/proc/stat" ]; then
grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {printf("%.1f%", usage)}'
elif [ is_osx ]; then
iostat -w 1 -c 2 -n 1 | tail -1 | awk '{usage=100-$6} END {printf("%d%%",usage)}';

View file

@ -13,6 +13,10 @@ is_osx() {
[ $(uname) == "Darwin" ]
}
is_cygwin() {
command -v WMIC > /dev/null
}
command_exists() {
local command="$1"
type "$command" >/dev/null 2>&1