File: man.sh

package info (click to toggle)
lf 28-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 640 kB
  • sloc: sh: 129; makefile: 22; csh: 4
file content (75 lines) | stat: -rwxr-xr-x 1,705 bytes parent folder | download
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
#!/bin/sh
# Generates `lf.1` man page using man macros with `go doc` output.
#
# This script is called in `doc.go` using `go generate` to generate a man page
# formatted with man macros from the documentation. A few additional sections
# such as `NAME` and `SYNOPSIS` are added to comply with man page conventions.
#
# Conversion logic implemented here from godoc output to man macros should not
# be considered compliant, as such it has inexact assumptions such as the use
# of spaces over tabs along with various corner cases that are not handled
# properly like character escaping. The intention here is to come up with
# something that can convert the current content in the documentation. For this
# reason, it is recommended to check the output after generation especially
# when the documentation is changed in a significant way.

out=lf.1

echo '.\" Code generated by gen/man.sh DO NOT EDIT.' > $out

cat << END >> $out
.TH LF 1
.SH NAME
lf \- terminal file manager
.SH SYNOPSIS
.SY lf
.OP \-command command
.OP \-config path
.OP \-cpuprofile path
.OP \-doc
.OP \-last-dir-path path
.OP \-log path
.OP \-memprofile path
.OP \-remote command
.OP \-selection-path path
.OP \-server
.OP \-single
.OP \-version
.OP \-help
.RI [ cd-or-select-path ]
.YS
.SH DESCRIPTION
END

go doc | awk '
BEGIN {
    RS = ""
    start = 1
}

# preformatted
/^ / {
    gsub("\\\\", "\\e", $0)
    print ".PP"
    print ".EX"
    print $0
    print ".EE"
    next
}

# heading
/^# *[^[:punct:]]*$/ {
    gsub(/# */, "", $0)
    print ".SH", toupper($0)
    start = 1
    next
}

# paragraph
{
    gsub("\n", " ", $0)
    gsub("\\\\", "\\e", $0)
    if (start) { start = 0 } else { print ".PP" }
    print $0
}
' >> $out