-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcpuScale.sh
More file actions
executable file
·102 lines (91 loc) · 2.02 KB
/
cpuScale.sh
File metadata and controls
executable file
·102 lines (91 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/sh
# Created By Nate Ober
# Nate [dot] Ober [at] Gmail
LBLUE='\033[0;36m';
DBLUE='\033[0;34m';
BLACK='\033[0;30m';
GREEN='\033[0;32m';
RED='\033[0;31m';
YELLOW='\033[0;33m';
WHITE='\033[0;37m';
LINES=20;
HIGHLIGHT=RED;
SYMBOL="__";
usage()
{
cat << EOF
usage: $0 options
This script will output a series of symbols with the symbol that represents the percent full highlighted in one of several colors.
I wrote this for use with Geektool. It is best operated in Geektool by using the "dot" convention ". /path/to/script.sh".
OPTIONS:
-h Highlight color. The color of the pipe line that indicates percent full.
Options are LBLUE, DBLUE, BLACK, GREEN, RED, YELLOW, WHITE. Default is RED.
-l Total number of divisor symbols. Default is 20.
-s The string to use as a divisor symbol. The default is a "__". (As you might expect, you must surround the string in quotes)
EOF
}
while getopts “:h:l:s:” OPTION
do
case $OPTION in
h)
HIGHLIGHT=$(echo "$OPTARG" | tr '[a-z]' '[A-Z]')
;;
l)
LINES="$OPTARG"
;;
s)
SYMBOL=$(printf '%s' $OPTARG)
;;
?)
usage
exit
;;
*)
usage
exit
;;
esac
done
if ! [[ "$LINES" =~ ^[0-9]+$ ]] ; then
usage
exit
fi
case $HIGHLIGHT in
LBLUE)
HIGHLIGHT=$LBLUE
;;
DBLUE)
HIGHLIGHT=$DBLUE
;;
BLACK)
HIGHLIGHT=$BLACK
;;
GREEN)
HIGHLIGHT=$GREEN
;;
RED)
HIGHLIGHT=$RED
;;
YELLOW)
HIGHLIGHT=$YELLOW
;;
WHITE)
HIGHLIGHT=$WHITE
;;
*)
usage
exit
;;
esac
CPUIDLE=`top -l 2 | grep -o '[0-9\.]\{3,5\}% idle' | awk 'NR==2{print}'`;
CPUUSAGE=`echo $CPUIDLE | awk '{printf "%.0f", 100 - $1}'`;
DIVTOT=`echo $CPUIDLE | awk -v lines=$LINES '{printf "%.0f", ($1/100)*lines}'`
echo "$CPUUSAGE%";
for ((i=1;i<$LINES;i++));do
if [ $i -ge $DIVTOT ]; then
echo "$(echo $HIGHLIGHT) $SYMBOL$(echo '\033[0m')";
else
echo " $SYMBOL";
fi
done
echo "cpu"