-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathupdate-readme.sh
More file actions
executable file
·55 lines (48 loc) · 1.16 KB
/
update-readme.sh
File metadata and controls
executable file
·55 lines (48 loc) · 1.16 KB
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
#!/usr/bin/env bash
set -exo pipefail
usage() {
echo "Usage: $0 [-D] [-M]" >&2
exit 1
}
desc=1
mdcmd=1
while getopts "DM" opt; do
case "$opt" in
D) desc= ;;
M) mdcmd= ;;
*) usage ;;
esac
done
shift "$((OPTIND -1))"
# Exec+Update README code blocks
if [ -n "$mdcmd" ]; then
if ! mdcmd -C; then
echo "Error: mdcmd -C failed" >&2
exit 1
fi
fi
# Update README subtitle
# Extract count from count-completions.sh output in README
n="$(grep -m1 '^# [0-9]' README.md | awk '{print $2}')"
if [ -z "$n" ]; then
echo "Error: Could not extract completion count from README (did count-completions.sh run successfully?)" >&2
exit 1
fi
ns="$(LC_NUMERIC=en_US.UTF-8 printf "%'d" "$n")"
in=README.md
out=README.tmp
head -n1 "$in" > "$out"
echo "[$ns](#count-completions) Git aliases and scripts." >> "$out"
tail -n+3 "$in" >> "$out"
mv "$out" "$in"
# Update repo description
if [ -n "$desc" ]; then
d0="$(gh repo view --json description -q .description)"
d1="$ns Git aliases and scripts"
if [ "$d0" = "$d1" ]; then
echo "Description unchanged: $d1" >&2
else
echo "Updating description: $d1" >&2
gh repo edit -d "$d1"
fi
fi