Repository navigation
Expand file tree
/
Copy pathusageToMarkdown
More file actions
executable file
·121 lines (108 loc) · 2.63 KB
/
Copy pathusageToMarkdown
File metadata and controls
executable file
·121 lines (108 loc) · 2.63 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
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
#!/usr/bin/sed -f
# Add auto-generation warning and level 1 heading.
1i\
<!-- This file is automatically generated by "make doc".\
DO NOT EDIT! Any changes made to this file will be overwritten.\
-->\
\
# [todo.txt-cli](http://todotxt.org) Usage\
# Format usage as code block.
s/^ Usage: .*$/```\
&\
```/
t
:restart
# Level 2 headings.
s/^ \([[:alpha:]].*\):$/## \1/
# Level 3 headings need more processing.
/^ [^[:space:]]/{
N
b levelThree
}
# Backslashes and underscores need to be escaped for Markdown.
s/\\/\\\\/g
s/_/\\_/g
# Lists have an indent of 10 spaces.
s/^ \{10\}\([^[:space:]].*\)/* \1/
# Anything else with more than 4 spaces of indentation is plain text.
s/^ \{5,\}//
b
:levelThree
# Format options.
s/^ \(-[^[:space:]]\{1,\}.*\)\n/### \1\
\
/
t printAndRestartWithLastLine
# Format environment variables with single-quoted value and optional appended description.
s/^ \(TODOTXT_[^[:space:]]\{1,\}\)\(='[^']*'\)\([[:space:]]\{1,\}\(.*\)\)\{0,1\}\n/### \1\
\
```shell\
\1\2\
```\
\
\4\
\
/
t printAndRestartWithLastLine
# Format environment variables with single WORD value and optional appended description.
s/^ \(TODOTXT_[^[:space:]]\{1,\}\)\(=[^[:space:]]*\)\([[:space:]]\{1,\}\(.*\)\)\{0,1\}\n/### \1\
\
```shell\
\1\2\
```\
\
\4\
\
/
t printAndRestartWithLastLine
# Format environment variables without value and mandatory appended description.
s/^ \(TODOTXT_[^[:space:]]\{1,\}\)[[:space:]]\{1,\}\(.*\)\n/### \1\
\
\2\
\
/
t printAndRestartWithLastLine
# Special handling of addm that has a single shell command over two lines.
s/^ \([^[:space:]]\{1,\}\)\( "[^"]*\)\n \([^[:space:]][^"]*"\)$/### \1\
\
```shell\
$ todo.sh \1\2\
\3\
```\
/
# No lookahead
t
# Handle actions (like add|a) that have a short alias.
s/^ \([^[:space:]]\{1,\}\)\(.*\)\n \([^[:space:]]\{1,\}\)\(.*\)$/### \1\
\
```shell\
$ todo.sh \1\2\
$ todo.sh \3\4\
```\
/
t printAndRestartWithLastLine
# Normal actions.
s/^ \([^[:space:]]\{1,\}\)\(.*\)\n/### \1\
\
```shell\
$ todo.sh \1\2\
```\
/
# The lookahead line didn't belong to the action, so print all lines that render
# the action and restart processing with the lookahead line in pattern space.
:printAndRestartWithLastLine
# Escape underscores (found in the environment variables) in the added heading
# (i.e. the first line), but not in the (following) code block.
y/\n//
# XXX: In POSIX sed, [^\n]* is ineffective and matches like .*; work around by
# temporarily translating newlines to another unused character.
s/^\([^\]*\)_\([^]*\)/\1\\_\2/
t printAndRestartWithLastLine
y//\n/
:printAndRestartLoop
/\n/!b restart
P
y/\n//
s/^[^]*//
y//\n/
b printAndRestartLoop