summaryrefslogtreecommitdiff
path: root/src/lib/librelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/librelib')
-rwxr-xr-xsrc/lib/librelib39
1 files changed, 28 insertions, 11 deletions
diff --git a/src/lib/librelib b/src/lib/librelib
index 2dc9314..d0a06e5 100755
--- a/src/lib/librelib
+++ b/src/lib/librelib
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
-# Copyright (c) 2013 by Luke Shumaker <lukeshu@sbcglobal.net>
+# Copyright (C) 2013-2014 by Luke Shumaker <lukeshu@sbcglobal.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,25 +16,39 @@
default_libdir=/usr/lib/libretools
-if ! type gettext &>/dev/null; then
- gettext() { echo "$@"; }
+if type gettext &>/dev/null; then
+ _() { gettext "$@"; }
+else
+ _() { echo "$@"; }
fi
+_l() {
+ TEXTDOMAIN='librelib' TEXTDOMAINDIR='/usr/share/locale' "$@"
+}
+
print() {
- mesg=$1
+ local mesg="$(_ "$1")"
shift
- printf -- "$(gettext "$mesg")\n" "$@"
+ printf -- "$mesg\n" "$@"
+}
+
+_html_whitespace_collapse() {
+ [[ $# == 0 ]] || panic
+ tr '\n' ' ' | sed -r -e 's/\t/ /g' -e 's/ +/ /g'
}
prose() {
- print "$@" | fmt -su
+ [[ $# -ge 1 ]] || panic
+ local mesg="$(_ "$(_html_whitespace_collapse <<<"$1")")"; shift
+ printf -- "$mesg" "$@" | fmt -u
}
cmd=${0##*/}
usage() {
. libremessages
print 'Usage: . $(%s LIBRARY)' "$cmd"
- print "Finds a shell library file"
+ print 'Usage: %s -h' "$cmd"
+ print "Finds a Bash library file"
echo
prose "While some libraries can be sourced just by their name because
they are installed in PATH (like libremessages), some are not
@@ -45,16 +59,19 @@ usage() {
changed with the environmental variable LIBRETOOLS_LIBDIR.' "$default_libdir"
echo
print "Example usage:"
- printf ' . $(%s conf.sh)\n' "$cmd"
+ printf ' . $(%s conf)\n' "$cmd"
+ echo
+ print "Options:"
+ flag '-h' 'Show this message'
}
main() {
if [[ $# != 1 ]]; then
- usage >&2
+ _l usage >&2
return 2
fi
if [[ $1 == '-h' ]]; then
- usage
+ _l usage
return 0;
fi
@@ -72,7 +89,7 @@ main() {
return 0;
fi
done
- print '%s: could not find library: %s' "$cmd" "$lib" >> /dev/stderr
+ _l print '%s: could not find library: %s' "$cmd" "$lib" >&2
return 1
}