-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_readme.sh
executable file
·42 lines (31 loc) · 1.04 KB
/
update_readme.sh
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
#!/bin/bash
## Update the completed progress at the bottom of README.md ##
# set manually by default
TOTAL=1268 # actual number of algorithm problems, 1268 @ 18th, Nov., 2019
SCALE=100
# count files in ./src/
COMPLETED=`ls src -l |grep "^-"|wc -l`
# update total number from shell input. otherwise use defalt value
if [ $# == 1 ]; then
TOTAL=$1
fi
ACCURATE_RATE=`echo "($COMPLETED * $SCALE) / $TOTAL" | bc -l`
RATE=`printf "%.2f" $ACCURATE_RATE`
ARROWS=$(printf "%d" `echo "$ACCURATE_RATE+0.5" | bc`)
DASHES=`echo "100-$ARROWS" | bc`
STR_ARROWS=`printf "%-${ARROWS}s" ">"`
STR_DASHES=`printf "%-${DASHES}s" "-"`
function delete() {
sed -i '/```/d' README.md
sed -i '/Progress/d' README.md
sed -i '/>-/d' README.md
}
function update() {
echo "\`\`\`" >> README.md
echo "Progress: $RATE% finished. [$COMPLETED solved of total $TOTAL algorithm problems]" >> README.md
echo "${STR_ARROWS// />}${STR_DASHES// /-}" >> README.md
echo "\`\`\`" >> README.md
}
delete
update
echo "progress updated to $RATE ($COMPLETED/$TOTAL)"