Skip to content
Permalink
e77f32591d
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
153 lines (127 sloc) 3.85 KB
#!/bin/bash
#
# beefind - scan directory and print files
#
# Copyright (C) 2009-2016
# Tobias Dreyer <dreyer@molgen.mpg.de>
# Marius Tolzmann <m@rius.berlin>
# and other bee developers
#
# This file is part of bee.
#
# bee 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 3 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/>.
BEE_VERSION="@BEE_VERSION@"
: ${BEE_LIBEXECDIR:=@LIBEXECDIR@}
: ${BEE_BINDIR:=@BINDIR@}
. ${BEE_LIBEXECDIR}/bee/beelib.config.sh
: ${BEEGETOPT:=${BEE_BINDIR}/beegetopt}
function usage() {
cat <<-EOF
beefind v${BEE_VERSION} 2009-2016
by Tobias Dreyer <dreyer@molgen.mpg.de> and Marius Tolzmann <m@rius.berlin>
Usage: beefind [options] <directory>
Options:
-c, --cutroot <path> strip <path> from printed files
-e, --exclude <pattern> ignore files matching <pattern>
-s, --exclude-list <file> ignore files matching pattern described in <file>
-o, --output <file> output is redirected into <file> instead of <stdout>
-h, --help display this help
EOF
}
function do_beefind() {
local options=$(${BEEGETOPT} --name beefind \
--option cutroot/c \
--option exclude/e= \
--option exclude-list/E= \
-- "${@}")
if [ $? != 0 ] ; then
usage
exit 1
fi
eval set -- "${options}"
declare find_format="%p\n"
declare -a OPT_EXCLUDE
declare -a OPT_EXCLUDELIST
while true ; do
case "${1}" in
--cutroot)
find_format="/%P\n"
shift 1
;;
--exclude)
OPT_EXCLUDE=( "${OPT_EXCLUDE[@]}" "${2}" )
shift 2
;;
--exclude-list)
OPT_EXCLUDELIST=( "${OPT_EXCLUDELIST[@]}" "${2}" )
shift 2
;;
--)
shift
break
;;
esac
done
if [ -z "${@}" ] ; then
usage
exit 1
fi
dirs=( "${@}" )
grep \
--extended-regexp \
--invert-match \
--file=<(if [ "${#OPT_EXCLUDELIST[@]}" -gt 0 ] ; then
grep --invert-match --regexp="^ *$" ${OPT_EXCLUDELIST[@]}
fi) \
--file=<(for p in ${OPT_EXCLUDE[@]} ; do
echo ${p}
done) \
<(find ${dirs[@]} -mindepth 1 -xdev -printf ${find_format})
}
###############################################################################
###############################################################################
###############################################################################
options=$(${BEEGETOPT} --name beefind \
--option output/o= \
--option help/h \
-- "${@}")
if [ $? != 0 ] ; then
usage
exit 1
fi
eval set -- "${options}"
declare OPT_OUTPUT=
while true ; do
case "${1}" in
--output)
OPT_OUTPUT="${2}"
shift 2
;;
--help)
usage
exit 0
;;
--)
shift
break
;;
esac
done
if [ -n "${OPT_OUTPUT}" ] ; then
if ! exec 1>${OPT_OUTPUT} ; then
print_warning "can't write to ${OPT_OUTPUT}"
exit 1
fi
fi
do_beefind "${@}"