-
Notifications
You must be signed in to change notification settings - Fork 0
/
droidtable
164 lines (149 loc) · 5.22 KB
/
droidtable
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/data/data/com.termux/files/usr/bin/bash
#set -x
function usage {
echo "Usage: ftable [options]"
echo ""
echo " options:"
echo " -n <SECS> seconds to wait between updates (Default: 2)"
}
NWAIT=2
while getopts ":n:h" arg; do
case ${arg} in
n)
if [[ "${OPTARG}" =~ ^[0-9]+$ ]]; then
NWAIT="${OPTARG}"
else
echo "ERROR: Invalid wait interval"
echo "Value must be an integer"
exit 1
fi
;;
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
# Making prettytable portable as 'prettyt'
# prettytable from https://github.com/jakobwesthoff/prettytable.sh
_ptable_char_top_left="┌"
_ptable_char_horiz="─"
_ptable_char_vert="│"
_ptable_char_bottom_left="└"
_ptable_char_bottom_right="┘"
_ptable_char_top_right="┐"
_ptable_char_vert_horiz_left="├"
_ptable_char_vert_horiz_right="┤"
_ptable_char_vert_horiz_top="┬"
_ptable_char_vert_horiz_bottom="┴"
_ptable_char_vert_horiz="┼"
# Default colors
_ptable_c_blue="0;34"
_ptable_c_green="0;32"
_ptable_c_cyan="0;36"
_ptable_c_red="0;31"
_ptable_c_purple="0;35"
_ptable_c_yellow="0;33"
_ptable_c_gray="1;30"
_ptable_c_light_blue="1;34"
_ptable_c_light_green="1;32"
_ptable_c_light_cyan="1;36"
_ptable_c_light_red="1;31"
_ptable_c_light_purple="1;35"
_ptable_c_light_yellow="1;33"
_ptable_c_light_gray="0;37"
# Somewhat special colors
_ptable_c_black="0;30"
_ptable_c_white="1;37"
_ptable_c_none="0"
function _ptable_prettify_lines() {
cat - | sed -e "s@^@${_ptable_char_vert}@;s@\$@ @;s@ @${_ptable_char_vert}@g"
}
function _ptable_fix_border_lines() {
cat - | sed -e "1s@ @${_ptable_char_horiz}@g;3s@ @${_ptable_char_horiz}@g;\$s@ @${_ptable_char_horiz}@g"
}
function _ptable_cize_lines() {
local color="$1"
local range="$2"
local ansicolor="$(eval "echo \${_ptable_c_${color}}")"
cat - | sed -e "${range}s@\\([^${_ptable_char_vert}]\\{1,\\}\\)@"$'\E'"[${ansicolor}m\1"$'\E'"[${_ptable_c_none}m@g"
}
function prettyt() {
local cols="${1}"
local color="${2:-none}"
local input="$(cat -)"
local header="$(echo -e "${input}" | head -n1)"
local body="$(echo -e "${input}" | tail -n+2)"
{
# Top border
echo -n "${_ptable_char_top_left}"
for i in $(seq 2 ${cols}); do
echo -ne "\t${_ptable_char_vert_horiz_top}"
done
echo -e "\t${_ptable_char_top_right}"
echo -e "${header}" | _ptable_prettify_lines
# Header/Body delimiter
echo -n "${_ptable_char_vert_horiz_left}"
for i in $(seq 2 ${cols}); do
echo -ne "\t${_ptable_char_vert_horiz}"
done
echo -e "\t${_ptable_char_vert_horiz_right}"
echo -e "${body}" | _ptable_prettify_lines
# Bottom border
echo -n "${_ptable_char_bottom_left}"
for i in $(seq 2 ${cols}); do
echo -ne "\t${_ptable_char_vert_horiz_bottom}"
done
echo -e "\t${_ptable_char_bottom_right}"
} | column -t -s $'\t' | _ptable_fix_border_lines | _ptable_cize_lines "${color}" "2"
}
fakewatch() {
while true; do
DATE=$(date)
RESULT=$("${@}")
clear
echo "$DATE"
echo "$RESULT"
read -t "$NWAIT" -n 1 k
if [[ $k = q ]]; then
break
fi
done
}
ftable() {
echo "Refreshing every $NWAIT seconds"
echo "Max freq will appear red" | grep --color=always -E -e '^' -e 'red'
echo ""
echo " Cortex-A55"
{
printf 'Core\tMHz\n'
printf '%s\t%s\n'
printf "$(paste <(cat /sys/devices/system/cpu/cpu{0..3}/cpufreq/scaling_cur_freq | awk -F : ' {printf "%3.f\n", $1/1000}') | nl -s ',' | tr -s '[[:space:]] ' | tr ',' '\t' | sed 's/ //g')"
} |
prettyt 2 blue |
grep --color=always -E -e '^' -e '1803'
echo ""
echo " Cortex-A76"
{
printf 'Core\tMHz\n'
printf '%s\t%s\n'
printf "$(paste <(cat /sys/devices/system/cpu/cpu{4..5}/cpufreq/scaling_cur_freq | awk -F : ' {printf "%3.f\n", $1/1000}') | nl -s ',' | tr -s '[[:space:]] ' | tr ',' '\t' | sed 's/ //g')"
} |
prettyt 2 blue |
grep --color=always -E -e '^' -e '2253'
echo ""
echo " Cortex-X1"
{
printf 'Core\tMHz\n'
printf '%s\t%s\n'
printf "$(paste <(cat /sys/devices/system/cpu/cpu{6..7}/cpufreq/scaling_cur_freq | awk -F : ' {printf "%3.f\n", $1/1000}') | nl -s ',' | tr -s '[[:space:]] ' | tr ',' '\t' | sed 's/ //g')"
} |
prettyt 2 blue |
grep --color=always -E -e '^' -e '2802'
echo "Press 'q' to quit"
}
fakewatch ftable