#!/usr/bin/env bash# Copyright (C) 2013-2014 Luke Shumaker <lukeshu@sbcglobal.net>## License: GNU GPLv2+## 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# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program. If not, see <http://www.gnu.org/licenses/>.
default_libdir=/usr/lib/libretools
iftypegettext&>/dev/null;then
_() {gettext"$@"; }else
_() {echo"$@"; }fi
_l() {
TEXTDOMAIN='librelib' TEXTDOMAINDIR='/usr/share/locale'"$@"}
print() {local mesg="$(_ "$1")"shiftprintf --"$mesg\n""$@"}
whitespace-collapse() {tr'\n''\r'|sed-r \
-e's/\r/ /g'-e's/\t/ /g' \
-e's/(^|[^.!? ]) +/\1 /g'-e's/([.!?]) +/\1 /g'}
prose() {local mesg="$(_ "$(whitespace-collapse <<<"$1")")";shiftprintf --"$mesg""$@"|fmt-u}
cmd=${0##*/}
usage() {
. libremessages
print 'Usage: . $(%s LIBRARY)'"$cmd"
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 installed there (like conf.sh), so a path must be given. Hardcoding that path is the way of the dark side."echo
prose 'By default, it looks for the files in `%s`, but this can be changed with the environmental variable LIBRETOOLS_LIBDIR.'"$default_libdir"echo
print "Example usage:"printf' . $(%s conf)\n'"$cmd"echo
print "Options:"
flag '-h''Show this message'}
main() {if[[$#!=1]];then
_l usage >&2return2fiif[[$1=='-h']];then
_l usage
return0;fiif[[-z$LIBRETOOLS_LIBDIR]];thenexport LIBRETOOLS_LIBDIR=$default_libdirfi
lib=$1
lib=${lib#libre}
lib=${lib%.sh}forfilein${lib} libre${lib} ${lib}.sh libre${lib}.sh;doif[[-f"$LIBRETOOLS_LIBDIR/$file"]];thenprintf'%s\n'"$LIBRETOOLS_LIBDIR/$file"return0;fidone
_l print '%s: could not find library: %s'"$cmd""$lib">&2return1}
main "$@"