-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-readme.sh
executable file
·40 lines (34 loc) · 1.11 KB
/
generate-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
#!/bin/bash
# Generates a `README.md` file describing all sibling scripts, through the parsing
# of each script header
FILE_NAME="README.md"
SCRIPTS=`find "$PWD" -maxdepth 2 | grep '\.sh'`
BUILD_NUMBER=`[[ ! -z $1 ]] && echo "(#$1)"`
print-script-parameters() {
parameters=$(
printf "$1" | grep '^\$' | awk '{printf "**%s** \n",$0} END {print ""}'
)
[[ ! -z "$parameters" ]] && printf "$parameters \n \n"
}
print-see-readme() {
readme_path="`dirname $1`/README.md"
[[ -f "$readme_path" ]] &&
[[ "$(dirname $readme_path)" != "$(dirname $FILE_NAME)" ]] &&
printf " \n>See [README.md]($readme_path) \n \n"
}
echo "\
# Shell Scripts
### This file is automatically generated by \``basename "$0"`\` script, \
triggered by Travis CI $BUILD_NUMBER
" > "$FILE_NAME"
for script in $SCRIPTS; do
script_name=`echo $script | sed "s|$(pwd)/||"`
script_header=$(sed '/^#!/d;/^$/q;s/^# //' $script)
script_description=$(printf "$script_header" | grep -v '^\$')
echo "\
## \`$script_name\`
- $script_description
`print-script-parameters "$script_header"`\
`print-see-readme "$script_name"`\
" >> "$FILE_NAME"
done