Skip to content

Commit cfa750f

Browse files
committed
Adding files
0 parents  commit cfa750f

File tree

3 files changed

+169
-0
lines changed

3 files changed

+169
-0
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frequency-table
2+
3+
![ftable](/ftable.png)
4+
5+
## Usage
6+
`ftable [options]`
7+
8+
``` options:
9+
-m <1000-9999> highlight frequencies above threshold
10+
-n <SECS> seconds to wait between updates (Default: 2)```

ftable

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/usr/bin/env bash
2+
3+
function usage {
4+
echo "Usage: ftable [options]"
5+
echo ""
6+
echo " options:"
7+
echo " -m <1000-9999> highlight frequencies above threshold"
8+
echo " -n <SECS> seconds to wait between updates (Default: 2)"
9+
}
10+
11+
XMMM=9
12+
MXMM=9
13+
MMXM=9
14+
MMMX=9
15+
NWAIT=2
16+
17+
while getopts ":m:n:h" arg; do
18+
case ${arg} in
19+
m)
20+
THRESH=$OPTARG
21+
if [[ $THRESH -ge 1000 && $THRESH -le 9999 ]]; then
22+
XMMM=$(echo ${THRESH:0:1})
23+
MXMM=$(echo ${THRESH:1:1})
24+
MMXM=$(echo ${THRESH:2:1})
25+
MMMX=$(echo ${THRESH:3:1})
26+
else
27+
echo "ERROR: Invalid MHz threshold"
28+
echo "Value must be between 1000-9999 MHz"
29+
exit
30+
fi
31+
;;
32+
n)
33+
if [[ "${OPTARG}" =~ ^[0-9]+$ ]]; then
34+
NWAIT="${OPTARG}"
35+
else
36+
echo "ERROR: Invalid wait interval"
37+
echo "Value must be an integer"
38+
exit 1
39+
fi
40+
;;
41+
h)
42+
usage
43+
exit 0
44+
;;
45+
*)
46+
usage
47+
exit 1
48+
;;
49+
esac
50+
done
51+
52+
# Making prettytable portable as 'prettyt'
53+
# prettytable from https://github.com/jakobwesthoff/prettytable.sh
54+
_ptable_char_top_left=""
55+
_ptable_char_horiz=""
56+
_ptable_char_vert=""
57+
_ptable_char_bottom_left=""
58+
_ptable_char_bottom_right=""
59+
_ptable_char_top_right=""
60+
_ptable_char_vert_horiz_left=""
61+
_ptable_char_vert_horiz_right=""
62+
_ptable_char_vert_horiz_top=""
63+
_ptable_char_vert_horiz_bottom=""
64+
_ptable_char_vert_horiz=""
65+
# Default colors
66+
_ptable_c_blue="0;34"
67+
_ptable_c_green="0;32"
68+
_ptable_c_cyan="0;36"
69+
_ptable_c_red="0;31"
70+
_ptable_c_purple="0;35"
71+
_ptable_c_yellow="0;33"
72+
_ptable_c_gray="1;30"
73+
_ptable_c_light_blue="1;34"
74+
_ptable_c_light_green="1;32"
75+
_ptable_c_light_cyan="1;36"
76+
_ptable_c_light_red="1;31"
77+
_ptable_c_light_purple="1;35"
78+
_ptable_c_light_yellow="1;33"
79+
_ptable_c_light_gray="0;37"
80+
# Somewhat special colors
81+
_ptable_c_black="0;30"
82+
_ptable_c_white="1;37"
83+
_ptable_c_none="0"
84+
85+
function _ptable_prettify_lines() {
86+
cat - | sed -e "s@^@${_ptable_char_vert}@;s@\$@ @;s@ @ ${_ptable_char_vert}@g"
87+
}
88+
89+
function _ptable_fix_border_lines() {
90+
cat - | sed -e "1s@ @${_ptable_char_horiz}@g;3s@ @${_ptable_char_horiz}@g;\$s@ @${_ptable_char_horiz}@g"
91+
}
92+
93+
function _ptable_cize_lines() {
94+
local color="$1"
95+
local range="$2"
96+
local ansicolor="$(eval "echo \${_ptable_c_${color}}")"
97+
cat - | sed -e "${range}s@\\([^${_ptable_char_vert}]\\{1,\\}\\)@"$'\E'"[${ansicolor}m\1"$'\E'"[${_ptable_c_none}m@g"
98+
}
99+
100+
function prettyt() {
101+
local cols="${1}"
102+
local color="${2:-none}"
103+
local input="$(cat -)"
104+
local header="$(echo -e "${input}" | head -n1)"
105+
local body="$(echo -e "${input}" | tail -n+2)"
106+
{
107+
# Top border
108+
echo -n "${_ptable_char_top_left}"
109+
for i in $(seq 2 ${cols}); do
110+
echo -ne "\t${_ptable_char_vert_horiz_top}"
111+
done
112+
echo -e "\t${_ptable_char_top_right}"
113+
echo -e "${header}" | _ptable_prettify_lines
114+
# Header/Body delimiter
115+
echo -n "${_ptable_char_vert_horiz_left}"
116+
for i in $(seq 2 ${cols}); do
117+
echo -ne "\t${_ptable_char_vert_horiz}"
118+
done
119+
echo -e "\t${_ptable_char_vert_horiz_right}"
120+
echo -e "${body}" | _ptable_prettify_lines
121+
# Bottom border
122+
echo -n "${_ptable_char_bottom_left}"
123+
for i in $(seq 2 ${cols}); do
124+
echo -ne "\t${_ptable_char_vert_horiz_bottom}"
125+
done
126+
echo -e "\t${_ptable_char_bottom_right}"
127+
} | column -t -s $'\t' | _ptable_fix_border_lines | _ptable_cize_lines "${color}" "2"
128+
}
129+
130+
fakewatch() {
131+
while true; do
132+
DATE=$(date)
133+
RESULT=$("${@}")
134+
clear
135+
echo "$DATE"
136+
echo "$RESULT"
137+
read -t "$NWAIT" -n 1 k
138+
if [[ $k = q ]]; then
139+
break
140+
fi
141+
done
142+
}
143+
144+
ftable() {
145+
echo "Refreshing every $NWAIT seconds"
146+
if [[ -n $THRESH ]]; then
147+
echo "Watching for frequency above $THRESH MHz" | grep --color=always -E -e '^' -e "[$XMMM-9][$MXMM-9][$MMXM-9][$MMMX-9]"
148+
fi
149+
{
150+
printf 'Core\tMHz\tCore\tMHz\n'
151+
printf '%s\t%s\t%s\t%s\n'
152+
printf "$(grep 'cpu MHz' /proc/cpuinfo | choose 3 | nl --number-format=ln | pr -2 -t | grep 'cpu MHz' /proc/cpuinfo | choose 3 | nl -s ',' | column -t | pr -2 -t | tr -s '[[:space:]] ' | tr ',' '\t' | sed 's/ //g')"
153+
} |
154+
prettyt 4 blue |
155+
grep --color=always -E -e '^' -e "[$XMMM-9][$MXMM-9][$MMXM-9][$MMMX-9]"
156+
echo "Press 'q' to quit"
157+
}
158+
159+
fakewatch ftable

ftable.png

15.3 KB
Loading

0 commit comments

Comments
 (0)