-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_man_page
More file actions
executable file
·62 lines (58 loc) · 1.55 KB
/
gen_man_page
File metadata and controls
executable file
·62 lines (58 loc) · 1.55 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
#!/usr/bin/env bash
readonly -a EXCLUDED_EXTENSIONS=(
'.txt'
'.md'
'.png'
'.jpeg'
'.jpg'
'.gz'
'.tar'
)
show_help() {
local -r ORIG_IFS="$IFS"
IFS=","; extensions="${EXCLUDED_EXTENSIONS[*]}"; IFS="$ORIG_IFS"
cat << __EOF__
Generates and compresses a man file in the local directory for the given command. Depends on help2man.
Usage: $0 COMMAND [SECTION]
or: $0 --all
or: $0 --help
or: $0 --version
Options:
--all: runs this command for all files in the current directory that don't start with a . and don't end with an excluded extension. These include ${extensions//,/', '}.
__EOF__
}
show_version() {
cat << __EOF__
$0 1.2.0
Copyright (C) 2025 Justin Morris
__EOF__
}
if [[ "$1" == "--help" ]]; then
show_help
exit
elif [[ "$1" == "--version" ]]; then
show_version
exit
elif [[ "$1" == "--all" ]]; then
((all=0, made=0, failed=0, skipped=0))
ORIG_IFS="$IFS"
IFS="|"; extensions="${EXCLUDED_EXTENSIONS[*]}"; IFS="$ORIG_IFS"
echo -n "All: $all, Successful: $made, Failed: $failed, Skipped: $skipped"
find . -maxdepth 1 -not -type d | grep -E -e "^\./\.|(($extensions)$)" -v - | while read -r line; do
((all++))
if eval "${line:2} --help" &>/dev/null && eval "${line:2} --version" &>/dev/null; then
if help2man -N "${line:2}" | gzip - >| "./man/man1/${line:2}.1.gz"; then
((made++))
else
((failed++))
fi
else
((skipped++))
fi
echo -n $'\r'; tput el
echo -n "All: $all, Successful: $made, Failed: $failed, Skipped: $skipped"
done
echo -n $'\n'
exit
fi
help2man -N --section="${2:-1}" "$1" | gzip - >| "./man/man${2:-1}/$1.1.gz"