-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-readme.sh
executable file
·55 lines (53 loc) · 1.44 KB
/
gen-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
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
file=README.md
tmp=$file.tmp
grep -A1 -n '| Number' $file\
| tail -n 1\
| cut -d- -f1\
| xargs -I{} sh -c "head $file -n {}"\
> $tmp
mv $tmp $file
for i in $(ls src | sort -nr); do
f="src/$i/$(echo $i | cut -d- -f2).*"
if ! ls $f 1> /dev/null 2>&1; then
# echo "$f could not be expanded"
continue
fi
f=$(ls $f)
printf "| $(echo $i | cut -d- -f1 | sed 's#^0*##') | [" >> $file
printf "$f" | sed -e 's!^.*/!! ; s!\..*$!! ; s!_! !g' >> $file
printf "]($f) | " >> $file
if [[ "$f" == *.py ]]; then
# Python
grep '# Difficulty: ' $f | sed 's!# Difficulty: !!' | tr -d '\n' >> $file
printf " | " >> $file
grep '# Questioner: ' $f | sed 's!# Questioner: !!' | tr -d '\n' >> $file
printf " | " >> $file
awk "NR>$(
grep -n '"""' $f\
| cut -d: -f1\
| head -n 2\
| sed '1!s#^#\&\&NR<#'\
| tr -d '\n')" $f\
| sed 's#$#<br/>#'\
| tr -d '\n'\
>> $file
echo " |" >> $file
elif [[ "$f" == *.cpp ]]; then
grep '// Difficulty' $f | sed 's!// Difficulty: !!' | tr -d '\n' >> $file
printf " | " >> $file
grep '// Questioner' $f | sed 's!// Questioner: !!' | tr -d '\n' >> $file
printf " | " >> $file
awk "NR>$(
grep -n '/\*' $f\
| cut -d: -f1)&&NR<$(
grep -n '\*/' $f\
| cut -d: -f1)" $f\
| sed 's#$#<br/>#'\
| tr -d '\n'\
>> $file
echo " |" >> $file
else
>&2 echo "File of unknown type: $f"
fi
done