-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathgen-readme.sh
executable file
·91 lines (79 loc) · 2.25 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh
#
# SCRIPT: gen-readme.sh
# AUTHOR: Janos Gyerik <[email protected]>
# DATE: 2012-06-14
# REV: 1.0.D (Valid are A, B, D, T and P)
# (For Alpha, Beta, Dev, Test and Production)
#
# PLATFORM: Not platform dependent
#
# PURPOSE: Generate README.md file from the usage messages.
#
# set -n # Uncomment to check your syntax, without execution.
# # NOTE: Do not forget to put the comment back in or
# # the shell script will not execute!
# set -x # Uncomment to debug this shell script (Korn shell only)
#
usage() {
test $# = 0 || echo "$@"
echo "Usage: $0 [OPTION]... [ARG]..."
echo
echo "Generate README.md file from the usage messages."
echo
echo Options:
echo " -h, --help Print this help"
echo
exit 1
}
args=
#arg=
#flag=off
#param=
while [ $# != 0 ]; do
case $1 in
-h|--help) usage ;;
# -f|--flag) flag=on ;;
# --no-flag) flag=off ;;
# -p|--param) shift; param=$1 ;;
# --) shift; while [ $# != 0 ]; do args="$args \"$1\""; shift; done; break ;;
-) usage "Unknown option: $1" ;;
-?*) usage "Unknown option: $1" ;;
*) args="$args \"$1\"" ;; # script that takes multiple arguments
# *) test "$arg" && usage || arg=$1 ;; # strict with excess arguments
# *) arg=$1 ;; # forgiving with excess arguments
esac
shift
done
eval "set -- $args" # save arguments in $@. Use "$@" in for loops, not $@
cd $(dirname "$0")
readme=README.md
cat <<"EOF" >$readme
Shell scripts
=============
Convenient shell scripts for everyday use, written in bash, perl, awk, python.
All scripts print a helpful usage message when used with `-h` or `--help`
The `./install.sh` script will symlink these scripts in your `~/bin`
directory. It will not overwrite any existing files.
EOF
print_section() {
printf "## $1\n\n" >> $readme
shift
for script; do
echo "* $script ..."
if [[ $script == *.awk ]]; then
usage=$(sed -ne 3s/..//p "$script")
else
usage=$(./"$script" -h | sed -ne 3p)
fi
test "$usage" || usage=TODO
cat <<EOF >>$readme
* $script
$usage
EOF
done
}
print_section Bash bash/*.sh
print_section Perl perl/*.pl
print_section Awk awk/*.awk
print_section Python python/*.py