From 94556b367f244289d38af450b4674ca1365d3a3d Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Fri, 4 Jul 2014 16:15:00 +0200 Subject: [PATCH] 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 --- Manual.md | 11 +++++++---- common/helpers/install.sh | 26 +++++++++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Manual.md b/Manual.md index f7fd6fa104d..8f556618480 100644 --- a/Manual.md +++ b/Manual.md @@ -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
[]` +- *vman()* `vman []` - Installs `file` into usr/share/man/
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 []` diff --git a/common/helpers/install.sh b/common/helpers/install.sh index f62ea5de946..3381e9ea6e7 100644 --- a/common/helpers/install.sh +++ b/common/helpers/install.sh @@ -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:
\n" + if [ $# -lt 1 ]; then + msg_red "$pkgver: vman: 1 argument expected: \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() {