mirror of https://github.com/mkerrisk/man-pages
scripts/bash_aliases: man_section(): Accept multiple sections
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com> Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
parent
3a42b0815e
commit
a3ccd456f3
|
@ -85,26 +85,35 @@ function grep_syscall_def()
|
||||||
########################################################################
|
########################################################################
|
||||||
# Linux man-pages
|
# Linux man-pages
|
||||||
|
|
||||||
# man_section() prints a specific manual page section (DESCRIPTION, SYNOPSIS,
|
# man_section() prints specific manual page sections (DESCRIPTION, SYNOPSIS,
|
||||||
# ...) of all manual pages in a directory (or in a single manual page file).
|
# ...) of all manual pages in a directory (or in a single manual page file).
|
||||||
# Usage example: .../man-pages$ man_section man2 SYNOPSIS;
|
# Usage example: .../man-pages$ man_section man2 SYNOPSIS 'CONFORMING TO';
|
||||||
|
|
||||||
function man_section()
|
function man_section()
|
||||||
{
|
{
|
||||||
if ! [ -v 2 ]; then
|
if ! [ -v 2 ]; then
|
||||||
>&2 echo "Usage: ${FUNCNAME[0]} <dir> <section>";
|
>&2 echo "Usage: ${FUNCNAME[0]} <dir> <section>...";
|
||||||
return ${EX_USAGE};
|
return ${EX_USAGE};
|
||||||
fi
|
fi
|
||||||
|
|
||||||
find "${1}" -type f \
|
local page="$1";
|
||||||
|xargs grep -l "\.SH ${2}" \
|
shift;
|
||||||
|
local sect="$@";
|
||||||
|
|
||||||
|
find "${page}" -type f \
|
||||||
|
|xargs wc -l \
|
||||||
|
|grep -v -e '\b1 ' -e '\btotal\b' \
|
||||||
|
|awk '{ print $2 }' \
|
||||||
|sort -V \
|
|sort -V \
|
||||||
|while read -r manpage; do
|
|while read -r manpage; do
|
||||||
<${manpage} \
|
cat \
|
||||||
sed -n \
|
<(<${manpage} sed -n '/^\.TH/,/^\.SH/{/^\.SH/!p}') \
|
||||||
-e '/^\.TH/,/^\.SH/{/^\.SH/!p}' \
|
<(for s in ${sect}; do
|
||||||
-e "/^\.SH ${2}/p" \
|
<${manpage} \
|
||||||
-e "/^\.SH ${2}/,/^\.SH/{/^\.SH/!p}" \
|
sed -n \
|
||||||
|
-e "/^\.SH ${s}/p" \
|
||||||
|
-e "/^\.SH ${s}/,/^\.SH/{/^\.SH/!p}"; \
|
||||||
|
done;) \
|
||||||
|man -P cat -l - 2>/dev/null;
|
|man -P cat -l - 2>/dev/null;
|
||||||
done;
|
done;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue