-
Notifications
You must be signed in to change notification settings - Fork 6
/
genReadme.sh
executable file
·54 lines (44 loc) · 1.25 KB
/
genReadme.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
#!/bin/bash
########################################
# gather all scripts info and generate Markdown README
#
# the markdown format README is an overview of all scripts
# it could be used at Bitbucket or Github
#
# The script requires all script following a rule that
# short introduction was written in certain line
#
# Kai Yuan
# kent.yuan at gmail dot com
# 2011-11-01
########################################
if [[ "$#" != "2" ]]; then
cat <<EOF
script to generate md format README for Bitbucket or Github.
Usage:
$0 <short desc line No.> <top level title>
example: $0 3 myScripts
EOF
exit 2
fi
INFO=$1
H1=$2
README=README.md
echo -e "
**$README was generated by shell script \`$0\`**
" > $README
echo -e "#$H1" >> $README
# only get the 1st level sub-directories (excluding hidden stuffs)
for d in $(ls -dF *|grep "\/$")
do
echo -e "##$d\\n" >> $README
for f in $(ls -dF $d*|grep -Ev "\/$")
do
# awk line removing directory prefix and pushing INFO line to target file.
awk -v pre=$d -v idx=$1 -v target=$README \
'NR==idx{gsub(pre,"",FILENAME);\
gsub(/^#/,"");\
f=gsub(/\[STOP_USED\]/," [Deprecated] ");\
printf "\t- %-14s ---------- %s\n", (f?"*":"")FILENAME, $0 >> (target); exit; }' $f
done
done