-
Notifications
You must be signed in to change notification settings - Fork 0
/
sizeCalc
executable file
·45 lines (39 loc) · 1.34 KB
/
sizeCalc
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
#!/usr/bin/env bash
#| 1 - size binary (e.g. avr-size)
#| 2 - measurement type (flash or ram)
#| 3 - binary file (e.g. main.hex)
#| 4 - total available (flash/ram) in bytes
#| 5 - flash/ram text
case "$2" in
"flash")
USED=$("$1" "$3" | tail -n-1 | awk '{ print $1+$2 }')
;;
"ram")
USED=$("$1" "$3" | tail -n-1 | awk '{ print $2+$3 }')
;;
*)
echo "INVALID Measurement type: $2"
exit 1
esac
# Calculate total flash/ram used
TOTAL="$4"
PERCENTAGE=$((USED * 100 / TOTAL))
# Size Colors
if (( PERCENTAGE > 95 )); then COLOR="\e[5;31m"
elif (( PERCENTAGE > 90 )); then COLOR="\e[38;5;196m"
elif (( PERCENTAGE > 85 )); then COLOR="\e[38;5;202m"
elif (( PERCENTAGE > 80 )); then COLOR="\e[38;5;214m"
elif (( PERCENTAGE > 75 )); then COLOR="\e[38;5;220m"
elif (( PERCENTAGE > 70 )); then COLOR="\e[38;5;226m"
elif (( PERCENTAGE > 60 )); then COLOR="\e[38;5;154m"
elif (( PERCENTAGE > 50 )); then COLOR="\e[38;5;82m"
elif (( PERCENTAGE > 40 )); then COLOR="\e[38;5;40m"
elif (( PERCENTAGE > 30 )); then COLOR="\e[32m"
else COLOR="\e[38;5;32m"
fi
# Display Results
NAME="$5"
echo -e " \e[38;5;253m ${NAME}\e[m: ${COLOR}${PERCENTAGE}% \e[m ${USED} / ${TOTAL} B"
# Test all clr
#echo -e "\e[5;31m 95 \e[38;5;196m 90 \e[38;5;202m 85 \e[38;5;214m 80 \e[38;5;220m 75 \e[38;5;226m 70 \e[38;5;154m 60 \e[38;5;82m 50 \e[38;5;40m 40 \e[32m 30 \e[38;5;32m 20"
exit 0