forked from dspinellis/git-issue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync-docs.sh
executable file
·133 lines (122 loc) · 3.89 KB
/
sync-docs.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/sh
# shellcheck disable=SC1004,SC2039
#
# Shellcheck ignore list:
# - SC1004: This backslash+linefeed is literal. Break outside single quotes
# if you just want to break the line.
# Rationale: Required to continue sed(1) lines
# - SC2039: In POSIX sh, 'local' is undefined.
# Rationale: Local makes for better code and works on many modern shells
#
# (C) Copyright 2016-2019 Diomidis Spinellis
#
# This file is part of git-issue, the Git-based issue management system.
#
# git-issue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# git-issue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with git-issue. If not, see <http://www.gnu.org/licenses/>.
#
# Synchronize script and its documentation with the contents of the README file
SCRIPT_NAME=git-issue.sh
MAN_PAGE=git-issue.1
# Update usage information in the script based on README.md
{
sed -n '1,/^The following commands are available:/p' $SCRIPT_NAME
# Keep lines from `### start ` to `git issue git`
# shellcheck disable=SC2016
sed -E -n '/^### Start/,/^\* `git issue git`/ {
# Only keep listed commands or subheaders
/^\* |^### /!d
# Format headers by eliminating all preceding space
s/^### (.*)/\
\1/g
# Remove repetitive git issue
s/git issue //g
# Remove code markup
s/`//g
# Format commands, depending on length
s/^\* ([^:]{3}): / \1 /g
s/^\* ([^:]{4}): / \1 /g
s/^\* ([^:]{5}): / \1 /g
s/^\* ([^:]{6}): / \1 /g
s/^\* ([^:]{7}): / \1 /g
s/^\* ([^:]{8}): / \1 /g
s/^\* ([^:]{9}): / \1 /g
p
}' README.md | tee foo
sed -n '/^USAGE_EOF/,$p' $SCRIPT_NAME
} |
if [ "$1" = "--no-user-agent" ] ; then
cat
else
# Update user agent version
sed '/^USER_AGENT/s/\/tree.*/\/tree\/'"$(git rev-parse --short HEAD)/"
fi >newgi.sh
mv newgi.sh $SCRIPT_NAME
chmod +x git-issue.sh
# Update the specified man section from the specified README section
# pre-processing its body with the given sed command
replace_section()
{
local man_section="$1"
local md_section="$2"
local command="$3"
local extra_command="$4"
{
# Output until the specified section
sed -n "1,/^\\.SH $man_section/p" $MAN_PAGE
# Output specified section from README
echo '.\" Auto-generated content from README.md; do not edit this section'
# shellcheck disable=SC2016
sed -n "/^## $md_section/,/^## / {
$command"'
# Remove section titles
/^## /d
/^###/d
# Set code text with Courier (twice per line)
s/`/\\fC/;s/`/\\fP/
s/`/\\fC/;s/`/\\fP/
# Set italic text (twice per line; not when switched to Courier)
/\\fC/!s/_/\\fI/;/\\fC/!s/_/\\fP/
/\\fC/!s/_/\\fI/;/\\fC/!s/_/\\fP/
# Set first-level and second-level bullets
s/^\* /.IP "" 4\
/
s/^ \* /.IP "" 8\
/
s/^ \* /.IP "" 12\
/
# format urls
s/\[\([^]]*\)\](\([^)]*\))/\1 <\2>/
'"$extra_command"'
p
}' README.md
# Output the rest of the man page
sed -n "1,/^\\.SH $man_section/d;{/^\\.SH /,/xyzzy/p;}" $MAN_PAGE
} >man-$$.1
mv man-$$.1 $MAN_PAGE
}
# Update subcommands, implementation, and examples in the manual page
# from the README file
# shellcheck disable=SC2016
replace_section 'GIT ISSUE COMMANDS' 'Use' 's/^\* `\([^`]*\)`: /.RE\
.PP\
\\fB\1\\fP\
.RS 4\
/' 's/^ *//'
replace_section FILES 'Internals' '' 's/^ *//'
# shellcheck disable=SC2016
replace_section EXAMPLES 'Example session' '/```/d;/^###/N;s/^### \(.*\)/.fi\
.ft R\
.PP\
\1.ft C\
.nf/'