Skip to content

Commit 96e4990

Browse files
committed
local/bin: add scripts
1 parent 66f0036 commit 96e4990

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

local/bin/asciify

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/sh
2+
3+
if [ "$1" = "-h" ]; then
4+
cat <<EOF>&2
5+
Usage: ${0##*/} [FILES]
6+
7+
Convert non-ASCII characters to their ASCII equivalent. If no files are
8+
provided, use stdin.
9+
10+
Options:
11+
12+
-i: If files are provided, convert them in-place.
13+
14+
EOF
15+
exit
16+
fi
17+
18+
unset OPT
19+
if [ "$1" = "-i" ]; then
20+
OPT=-i
21+
shift
22+
fi
23+
24+
## Note that we also use 'sed -i' to edit files instead of 'ex'. Otherwise the
25+
## code looks ugly if we try to handle both stdin and files with only one
26+
## call. Besides, ex does not support multiple file editing.
27+
sed $OPT \
28+
-e 's/[áàâä]/a/g' \
29+
-e 's/[éèêë]/e/g' \
30+
-e 's/[íìîï]/i/g' \
31+
-e 's/[óòôö]/o/g' \
32+
-e 's/[úùûü]/u/g' \
33+
-e 's/[ýỳŷÿ]/y/g' \
34+
-e 's/[ÁÀÂÄ]/A/g' \
35+
-e 's/[ÉÈÊË]/E/g' \
36+
-e 's/[ÍÌÎÏ]/I/g' \
37+
-e 's/[ÓÒÔÖ]/O/g' \
38+
-e 's/[ÚÙÛÜ]/U/g' \
39+
-e 's/[ÝỲŶŸ]/Y/g' \
40+
-e 's/[ñ]/n/g' \
41+
-e 's/[œ]/oe/g' \
42+
-e 's/[Œ]/Oe/g' \
43+
-e 's/[æ]/ae/g' \
44+
-e 's/[Æ]/Ae/g' \
45+
-e 's/[ç]/c/g' \
46+
-e 's/[Ç]/C/g' \
47+
-e 's/[ß]/ss/g' \
48+
-e 's/[«»„“”‚‘’]/"/g' \
49+
-e 's/[©]/(C)/g' \
50+
-e 's/[®]/(R)/g' \
51+
-e 's/[™]/(TM)/g' \
52+
-e 's/[¥]/Y/g' \
53+
-e 's/[Ð]/D/g' \
54+
-e 's/[ŀ]/l/g' \
55+
-e 's/[Ŀ]/L/g' \
56+
-e 's/[€]/euro/g' \
57+
-e 's/[¢]/cent/g' \
58+
-e 's/[£]/pound/g' \
59+
-e 's/[µ]/mu/g' \
60+
-e 's/[²]/^2/g' \
61+
-e 's/[³]/^3/g' \
62+
-e 's/[¡]/!/g' \
63+
-e 's/[¿]/?/g' \
64+
-e 's/[–‑]/-/g' \
65+
-e 's/[…]/.../g' \
66+
-e 's/[≤]/<=/g' \
67+
-e 's/[≥]/>=/g' \
68+
-e 's/[±]/+\/-/g' \
69+
-e 's/[≠]/!=/g' \
70+
-e 's/[⋅]/./g' \
71+
-e 's/[×]/x/g' \
72+
-e 's/[÷]/\//g' \
73+
-e 's/[↓]/|/g' \
74+
-e 's/[↑]/^/g' \
75+
-e 's/[←]/<=/g' \
76+
-e 's/[→]/=>/g' \
77+
"$@"

local/bin/cpuusage

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/sh
2+
3+
if [ "$1" = "-h" ]; then
4+
cat <<EOF>&2
5+
Usage: ${0##*/}
6+
7+
Return the CPU usage. Linux only.
8+
9+
EOF
10+
exit
11+
fi
12+
13+
if [ ! "$(uname)" = "Linux" ]; then
14+
echo >&2 "Linux only."
15+
exit 1
16+
fi
17+
18+
19+
## CPU usage
20+
##
21+
## A typical CPU array is (on Linux Kernel 3.0)
22+
## cpu 158150 0 52354 18562746 1472 0 10198 0 0 0
23+
##
24+
## The meanings of the columns are as follows, from left to right:
25+
##
26+
## user: normal processes executing in user mode
27+
## nice: niced processes executing in user mode
28+
## system: processes executing in kernel mode
29+
## idle: twiddling thumbs
30+
## iowait: waiting for I/O to complete
31+
## irq: servicing interrupts
32+
## softirq: servicing softirqs
33+
## ... (see 'man 5 proc' for further details)
34+
##
35+
## Only the first 4 values are interesting here.
36+
37+
cpuarray="$(grep '^cpu ' /proc/stat)"
38+
## We start at field #3 since there are 2 spaces after 'cpu'.
39+
f1=$(echo "$cpuarray" | cut -f3 -d' ')
40+
f2=$(echo "$cpuarray" | cut -f4 -d' ')
41+
f3=$(echo "$cpuarray" | cut -f5 -d' ')
42+
f4=$(echo "$cpuarray" | cut -f6 -d' ')
43+
44+
totalA=$((f1+f2+f3+f4))
45+
idleA=$f4
46+
sleep 1
47+
48+
cpuarray="$(grep '^cpu ' /proc/stat)"
49+
f1=$(echo "$cpuarray" | cut -f3 -d' ')
50+
f2=$(echo "$cpuarray" | cut -f4 -d' ')
51+
f3=$(echo "$cpuarray" | cut -f5 -d' ')
52+
f4=$(echo "$cpuarray" | cut -f6 -d' ')
53+
54+
totalB=$((f1+f2+f3+f4))
55+
idleB=$f4
56+
57+
totaldiff=$((${totalB:-0}-${totalA:-0}))
58+
59+
if [ $totaldiff -eq 0 ]; then
60+
echo 0
61+
else
62+
echo "$((100 - 100 * (idleB-idleA) / totaldiff))"
63+
fi

0 commit comments

Comments
 (0)