change vman helper to automatically detect section

Given a filename like "foo.1" or "foo.fr.1", it is possible to calculate
the correct directory to install to, without requiring the user to
specify it.

Suggested-by: Christian Neukirchen <chneukirchen@gmail.com>
This commit is contained in:
Dominik Honnef 2014-07-04 16:15:00 +02:00
parent d59300a322
commit 94556b367f
2 changed files with 28 additions and 9 deletions

View File

@ -172,11 +172,14 @@ The optional 4th argument can be used to change the `file name`.
permissions 0755. The optional 2nd argument can be used to change
the `file name`.
- *vman()* `vman <file> <section> [<name>]`
- *vman()* `vman <file> [<name>]`
Installs `file` into usr/share/man/<section> in the pkg
`$DESTDIR`. The optional 3rd argument can be used to change the
`file name`.
Installs `file` as a man page. `vman()` parses the name and
determines the section as well as localization. Example mappings:
`foo.1` -> `${DESTDIR}/usr/share/man/man1/foo.1`
`foo.fr.1` -> `${DESTDIR}/usr/share/man/fr/man1/foo.1`
`foo.1p` -> `${DESTDIR}/usr/share/man/man1/foo.1p`
- *vdoc()* `vdoc <file> [<name>]`

View File

@ -29,15 +29,31 @@ _vbin() {
}
_vman() {
local file="$1" section="$2" targetfile="$3"
local file="$1" target="${2:-$1}"
if [ $# -lt 2 ]; then
msg_red "$pkgver: vman: 2 arguments expected: <file> <section>\n"
if [ $# -lt 1 ]; then
msg_red "$pkgver: vman: 1 argument expected: <file>\n"
return 1
fi
vmkdir "usr/share/man/${section}"
vinstall "$file" 644 "usr/share/man/${section}" "$3"
suffix=${target##*.}
if [[ $target =~ (.*)\.([a-z][a-z](_[A-Z][A-Z])?)\.(.*) ]]
then
name=${BASH_REMATCH[1]##*/}.${BASH_REMATCH[4]}
mandir=${BASH_REMATCH[2]}/man${suffix:0:1}
else
name=${name##*/}
mandir=man${suffix:0:1}
fi
if [[ ${mandir} == *man[0-9n] ]] ; then
vinstall "$file" 644 "usr/share/man/${mandir}" "$name"
return 0
fi
msg_red "$pkgver: vman: Filename '${target}' does not look like a man page\n"
return 1
}
_vdoc() {