faster, cleaner sass generation
[iankelling.org] / gitweb-descriptions
1 #!/bin/bash -l
2
3 # my projects all have README or --help with a short single line
4 # description which I parse and put into the gitweb description.
5
6 # If it's a repo with just a single bash script or *-function script,
7 # then call it with --help, grap the 2nd line.
8 # else, parse the readme, find the first non blank, not starting with [#*],
9 # and use that line.
10
11 set -eE -o pipefail
12 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
13
14 if [[ ! $1 ]]; then
15 echo "need gitroot arg"
16 exit 1
17 fi
18
19 gitroot=$1
20 cd $gitroot
21
22 shopt -s extglob
23
24 _git_desc_readme() {
25 while read -r line; do
26 [[ $line ]] || continue
27 if echo "$line" | grep "^ *[#*]" &>/dev/null; then
28 continue
29 fi
30 echo "$line" > .git/description
31 break
32 done < README*
33 }
34
35 dirs=()
36 for d in $gitroot/*; do
37 if [[ -d $d && ! -L $d ]]; then
38 for sub in $d/*; do
39 dirs+=($sub)
40 done
41 else
42 dirs+=($d)
43 fi
44 done
45
46 gitweb-descriptions() {
47 for d in ${dirs[@]}; do
48 d=$(readlink -f $d)
49 cd $d/..
50 e ${PWD##*/}
51 shopt -s nullglob
52 f=(!(LICENSE|COPYING|README|.git))
53 shopt -u nullglob
54 if [[ ${#f[@]} == 1 && ! -d $f ]]; then
55 if [[ ! -x $f ]]; then
56 if [[ $f == *-function ]]; then
57 ${f%-function} --help | sed -n '2p' > .git/description
58 else
59 _git_desc_readme
60 fi
61 else
62 $f --help | sed -n '2p' > .git/description
63 fi
64 else
65 _git_desc_readme
66 fi
67 done
68 }
69 gitweb-descriptions "$@"