Fossil SCM

fossil-scm / tools / man_page_command_list.tcl
Blame History Raw 69 lines
1
#!/usr/bin/env tclsh
2
# man_page_command_list.tcl - generates common command list for fossil.1
3
4
# Tunable configuration.
5
set columns 5
6
set width 15
7
8
# The only supported command-line argument is the optional output filename.
9
if {[llength $argv] == 1} {
10
set file [lindex $argv 0]
11
}
12
13
# Get list of common commands.
14
set commands [exec fossil help]
15
regsub -nocase {.*?\nfrequently used commands:.*\n} $commands {} commands
16
regsub -nocase {\nthis is fossil version.*} $commands {} commands
17
regsub -all {\s+} $commands " " commands
18
set commands [lsort $commands]
19
20
# Compute number of rows.
21
set rows [expr {([llength $commands] + $columns - 1) / $columns}]
22
23
# Generate text one line at a time.
24
set text {}
25
for {set row 0} {$row < $rows} {incr row} {
26
# Separate rows with line break.
27
if {$row} {
28
append text .br\n
29
}
30
31
# Generate the row of commands.
32
for {set col 0} {$col < $columns} {incr col} {
33
set i [expr {$col * $rows + $row}]
34
if {$i < [llength $commands]} {
35
append text [format %-*s $width [lindex $commands $i]]
36
}
37
}
38
append text \n
39
}
40
41
# Strip trailing whitespace from each line.
42
regsub -all {\s+\n} $text \n text
43
44
# Output text.
45
if {[info exists file]} {
46
# If a filename was specified, read the file for use as a template.
47
set chan [open $file]
48
set data [read $chan]
49
close $chan
50
51
# Locate the part of the file to replace.
52
if {[regexp -indices {\n\.SH Common COMMANDs:\n\n(.*?)\n\.SH} $data\
53
_ range]} {
54
# If found, replace with the updated command list.
55
set chan [open $file w]
56
puts -nonewline $chan [string replace $data\
57
[lindex $range 0] [lindex $range 1] $text]
58
close $chan
59
} else {
60
# If not found, abort.
61
error "could not find command list in man file \"$file\""
62
}
63
} else {
64
# If no filename was specified, write to stdout.
65
puts $text
66
}
67
68
# vim: set sts=4 sw=4 tw=80 et ft=tcl:
69

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button